Skip to content

Commit

Permalink
webapp: single-file mode (always pinned)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Sep 10, 2024
1 parent c91d52c commit 2e81534
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Diffedit3</title>
<script type="module" crossorigin src="/assets/index-DTwiRke5.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DCOZ1_NJ.css">
<script type="module" crossorigin src="/assets/index-Bm9grSBb.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-4W6tk22x.css">
</head>

<body>
Expand Down
20 changes: 18 additions & 2 deletions webapp/src/merge_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2e81534

Please sign in to comment.