Skip to content

Commit 8c55974

Browse files
committed
[FIX] borders: preserve side borders when combining External and All
When applying an External border on a range and then applying All borders on an inner/overlapping range, the side borders (left/right) of the inner cells were lost after re-opening the spreadsheet. The exported border data was correct, but the BordersPlugin recomputation logic in addBorder incorrectly cleared adjacent borders on import/update. The adjacency check (adjacent(existingBorder.zone, zone)) reported the side of the existing zone, but we were deciding whether to clear it based on the same side key in the new border, instead of the opposite side (shared edge) on the new zone. As a result, importing the combination of: C2:C4 with All borders B2:B4 with left/top/bottom D2:D4 with right/top/bottom ended up clearing the left and right borders of C2:C4. This commit adjusts the adjacent clearing logic to: Map the adjacent side of the existing zone to the opposite side on the new zone. Only clear the existing side if the corresponding opposite side is actually being written on the new border. Task: 5270171
1 parent 7ae8c76 commit 8c55974

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/plugins/core/borders.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ export class BordersPlugin extends CorePlugin<BordersPluginState> implements Bor
343343
const borders: ZoneBorder[] = [];
344344
const plannedBorder = newBorder ? { zone, style: newBorder } : undefined;
345345
const sideToClear = {
346-
left: force || !!newBorder?.left,
347-
right: force || !!newBorder?.right,
348-
top: force || !!newBorder?.top,
349-
bottom: force || !!newBorder?.bottom,
346+
left: force || !!newBorder?.right,
347+
right: force || !!newBorder?.left,
348+
top: force || !!newBorder?.bottom,
349+
bottom: force || !!newBorder?.top,
350350
};
351351
let editingZone: Zone[] = [zone];
352352
for (const existingBorder of this.borders[sheetId] ?? []) {

tests/borders/border_plugin.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,36 @@ describe("borders", () => {
147147
});
148148
});
149149

150+
test("Preserves side borders when combining external and all via command", () => {
151+
const model = new Model();
152+
const defaultBorder = DEFAULT_BORDER_DESC;
153+
154+
setBordersOnTarget(model, ["C2:C4"], {
155+
top: defaultBorder,
156+
bottom: defaultBorder,
157+
left: defaultBorder,
158+
right: defaultBorder,
159+
});
160+
setZoneBorders(model, { position: "hv" }, ["C2:C4"]);
161+
setBordersOnTarget(model, ["B2:B4"], {
162+
top: defaultBorder,
163+
bottom: defaultBorder,
164+
left: defaultBorder,
165+
});
166+
setBordersOnTarget(model, ["D2:D4"], {
167+
top: defaultBorder,
168+
bottom: defaultBorder,
169+
right: defaultBorder,
170+
});
171+
172+
expect(getBorder(model, "C2")).toEqual({
173+
top: defaultBorder,
174+
bottom: defaultBorder,
175+
left: defaultBorder,
176+
right: defaultBorder,
177+
});
178+
});
179+
150180
test("can set all borders in a zone", () => {
151181
const model = new Model();
152182

0 commit comments

Comments
 (0)