diff --git a/TODO.md b/TODO.md index e2f3b91..8921cf6 100644 --- a/TODO.md +++ b/TODO.md @@ -11,13 +11,13 @@ - [x] Save layouts when created in graphical editor - [x] Load layouts on extension initialization -### 2. Remove Last Zone Implementation (extension.js:236-274) +### 2. Remove Last Zone Implementation ✅ COMPLETED **Priority: Medium** -- [ ] `_removeLastZone()` destroys and recreates entire editor interface -- [ ] Causes visual flicker -- [ ] Inefficient approach -- [ ] Could leave dangling event listeners -- [ ] Refactor to only remove the last zone widget without recreating everything +- [x] `_removeLastZone()` destroys and recreates entire editor interface +- [x] Causes visual flicker +- [x] Inefficient approach +- [x] Could leave dangling event listeners +- [x] Refactor to only remove the last zone widget without recreating everything ## Functionality Improvements diff --git a/extension.js b/extension.js index d7c4c65..19cef23 100644 --- a/extension.js +++ b/extension.js @@ -548,53 +548,20 @@ ZoneEditor.prototype = { _removeLastZone: function() { if (this.zones.length > 0) { + // Remove the last zone from data this.zones.pop(); - // Also remove the last zone actor + // Remove and destroy the last zone actor if (this.zoneActors.length > 0) { let removedActor = this.zoneActors.pop(); this.editorOverlay.remove_child(removedActor); removedActor.destroy(); } - // Redraw editor - this._cancelEditor(); - this.startEditor(); - - // Re-add existing zones - let monitor = Main.layoutManager.primaryMonitor; - this.zoneActors = []; // Reset actors array - this.zones.forEach((zone, index) => { - let zoneActor = new St.Widget({ - style_class: 'gridsnap-editor-zone', - x: zone.x * monitor.width, - y: zone.y * monitor.height, - width: zone.width * monitor.width, - height: zone.height * monitor.height - }); - zoneActor.set_style( - 'border: 3px solid rgba(100, 255, 100, 0.9);' + - 'background-color: rgba(100, 255, 100, 0.3);' + - 'border-radius: 4px;' - ); - - let label = new St.Label({ - text: String(index + 1), - x: 10, - y: 10 - }); - label.set_style( - 'color: white;' + - 'font-size: 24px;' + - 'font-weight: bold;' + - 'text-shadow: 2px 2px 4px rgba(0,0,0,0.8);' - ); - zoneActor.add_child(label); - this.editorOverlay.add_child(zoneActor); - - // Track zone actors for moving - this.zoneActors.push(zoneActor); - }); + // Update zone numbers on remaining zones + // Since we removed the last zone, we only need to update if there are still zones + // The numbering is 1-indexed, so zone 0 displays "1", zone 1 displays "2", etc. + // No need to update numbers since we removed the last one - other numbers stay the same } },