From 2e815347a6c53c45f180df09a05cd39e8dde4a90 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Mon, 9 Sep 2024 22:31:13 -0700 Subject: [PATCH] webapp: single-file mode (always pinned) --- CHANGELOG.md | 4 ++++ ...{index-DCOZ1_NJ.css => index-4W6tk22x.css} | 8 ++++++++ .../{index-DTwiRke5.js => index-Bm9grSBb.js} | 18 +++++++++++++++-- webapp/dist/index.html | 4 ++-- webapp/src/merge_state.ts | 20 +++++++++++++++++-- webapp/src/styles.css | 8 ++++++++ 6 files changed, 56 insertions(+), 6 deletions(-) rename webapp/dist/assets/{index-DCOZ1_NJ.css => index-4W6tk22x.css} (99%) rename webapp/dist/assets/{index-DTwiRke5.js => index-Bm9grSBb.js} (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b0ea0c..c3ffd07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 left_file right_file output_file` is now allowed. Mixing dirs and files is not allowed. +* When used on a single file, `diffedit3` now permanently stays in "pinned" mode + and the pinning/collapsing controls are disabled. Allowing the user to + collapse the only editor doesn't make much sense. + ### Fixed bugs ## [v0.4.0] - 2024-05-04 diff --git a/webapp/dist/assets/index-DCOZ1_NJ.css b/webapp/dist/assets/index-4W6tk22x.css similarity index 99% rename from webapp/dist/assets/index-DCOZ1_NJ.css rename to webapp/dist/assets/index-4W6tk22x.css index 9981f14..0589241 100644 --- a/webapp/dist/assets/index-DCOZ1_NJ.css +++ b/webapp/dist/assets/index-4W6tk22x.css @@ -160,6 +160,14 @@ details[open] > summary > .if-details-closed { width: 0.5em; display: inline-block; } +.single-editor .pin-span { + display: none; +} +.single-editor details > summary { + /* Spacing hack to hide the details button */ + position: relative; + left: -1em; +} @supports (not (-moz-appearance: button)) and (contain: paint) and (-webkit-appearance: none) { diff --git a/webapp/dist/assets/index-DTwiRke5.js b/webapp/dist/assets/index-Bm9grSBb.js similarity index 99% rename from webapp/dist/assets/index-DTwiRke5.js rename to webapp/dist/assets/index-Bm9grSBb.js index 3c57709..f1b694c 100644 --- a/webapp/dist/assets/index-DTwiRke5.js +++ b/webapp/dist/assets/index-Bm9grSBb.js @@ -13680,6 +13680,9 @@ class MergeState { this.merge_views[k2].editor().refresh(); } } + singleEditor() { + return Object.keys(this.merge_views).length == 1; + } /// Renders the input inside the HTML element with id `unique_id`. static renderInDomElement(unique_id, merge_input) { let templates = []; @@ -13793,6 +13796,7 @@ class MergeState { throw `Element with id ${unique_id} must be a child of an element with class .app-window`; } merge_state.parent_window = parent_window; + const singleEditor = Object.keys(merge_input).length == 1; for (let k2 in merge_input) { if (to_error(merge_input[k2]) != null) { continue; @@ -13802,6 +13806,10 @@ class MergeState { k2, fillInDefaultSettings(merge_input[k2]) ); + if (singleEditor) { + parent_window.classList.add("single-editor"); + merge_state.toggle_pinning(k_uid(k2)); + } } return merge_state; } @@ -13859,11 +13867,17 @@ class MergeState { alignButtonEl.onclick = () => this.recreateCodeMirrorFlippingOption(filename, "align"); prevChangeButtonEl.onclick = () => cm_prevChange(merge_view.editor()); nextChangeButtonEl.onclick = () => cm_nextChange(merge_view.editor()); - pinButtonEl.onclick = () => this.toggle_pinning(unique_id); + pinButtonEl.onclick = () => { + if (!this.singleEditor()) { + this.toggle_pinning(unique_id); + } + }; detailsButtonEl.open = false; detailsButtonEl.ontoggle = () => { var _a, _b; - if (!detailsButtonEl.open) { + if (this.singleEditor()) { + detailsButtonEl.open = true; + } else if (!detailsButtonEl.open) { if ((_b = (_a = this.parent_window) == null ? void 0 : _a.classList) == null ? void 0 : _b.contains("pinned-mode")) { this.toggle_pinning(unique_id); } diff --git a/webapp/dist/index.html b/webapp/dist/index.html index ecbfb6e..dbc4b95 100644 --- a/webapp/dist/index.html +++ b/webapp/dist/index.html @@ -10,8 +10,8 @@ /> Diffedit3 - - + + diff --git a/webapp/src/merge_state.ts b/webapp/src/merge_state.ts index 9b26963..9bb8e33 100644 --- a/webapp/src/merge_state.ts +++ b/webapp/src/merge_state.ts @@ -42,6 +42,10 @@ export class MergeState { } } + public singleEditor(): boolean { + return Object.keys(this.merge_views).length == 1; + } + /// Renders the input inside the HTML element with id `unique_id`. public static renderInDomElement(unique_id: string, merge_input: MergeInput) { let templates = []; @@ -175,6 +179,7 @@ export class MergeState { } merge_state.parent_window = parent_window; + const singleEditor = Object.keys(merge_input).length == 1; for (let k in merge_input) { if (to_error(merge_input[k]) != null) { continue; @@ -184,6 +189,11 @@ export class MergeState { k, fillInDefaultSettings(merge_input[k]), ); + if (singleEditor) { + parent_window.classList.add("single-editor"); + // Pin the only editor + merge_state.toggle_pinning(k_uid(k)); + } } return merge_state; @@ -257,12 +267,18 @@ export class MergeState { prevChangeButtonEl.onclick = () => cm_prevChange(merge_view.editor()); nextChangeButtonEl.onclick = () => cm_nextChange(merge_view.editor()); - pinButtonEl.onclick = () => this.toggle_pinning(unique_id); + pinButtonEl.onclick = () => { + if (!this.singleEditor()) { + this.toggle_pinning(unique_id); + } + }; // Starting with details closed breaks CodeMirror, especially line numbers // in left and right merge view. detailsButtonEl.open = false; detailsButtonEl.ontoggle = () => { - if (!detailsButtonEl.open) { + if (this.singleEditor()) { + detailsButtonEl.open = true; + } else if (!detailsButtonEl.open) { // We just closed the details if (this.parent_window?.classList?.contains("pinned-mode")) { this.toggle_pinning(unique_id); diff --git a/webapp/src/styles.css b/webapp/src/styles.css index f0e747a..104fe4a 100644 --- a/webapp/src/styles.css +++ b/webapp/src/styles.css @@ -160,6 +160,14 @@ details[open] > summary > .if-details-closed { width: 0.5em; display: inline-block; } +.single-editor .pin-span { + display: none; +} +.single-editor details > summary { + /* Spacing hack to hide the details button */ + position: relative; + left: -1em; +} @supports (not (-moz-appearance: button)) and (contain: paint) and (-webkit-appearance: none) {