Skip to content

Commit f0a5de8

Browse files
Merge pull request #741 from NeurodataWithoutBorders/clear-selections-when-transitioning
Avoid needless selections and clear on transition
2 parents 3a1e8e6 + 290f16d commit f0a5de8

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/renderer/src/stories/Dashboard.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ export class Dashboard extends LitElement {
202202
}
203203

204204
setMain(page) {
205+
window.getSelection().empty(); // Remove user selection before transitioning
206+
205207
// Update Previous Page
206208
const info = page.info;
207209
const previous = this.page;

src/renderer/src/stories/table/Cell.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ export class TableCell extends LitElement {
219219
else if (this.schema.format === "date-time") {
220220
cls = DateTimeCell
221221
this.type = "date-time"
222-
} else if (this.schema.type === "object") {
222+
}
223+
224+
else if (this.schema.type === "object") {
223225
cls = NestedInputCell
224226
this.type = "table"
225227
}

src/renderer/src/stories/table/cells/base.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,33 @@ export class TableCellBase extends LitElement {
201201

202202
set(value: any, runOnChange = true) {
203203

204-
if (document.execCommand) {
204+
// Ensure all operations are undoable
205+
if (typeof InputEvent === 'function') {
205206
this.#editable.setAttribute('contenteditable', '')
206207
this.#editable.focus();
207-
document.execCommand('selectAll');
208-
document.execCommand('insertText', false, value);
208+
209+
const range = document.createRange();
210+
range.selectNodeContents(this.#editable);
211+
const sel = window.getSelection()!;
212+
sel.removeAllRanges();
213+
sel.addRange(range);
214+
215+
const inputEvent = new InputEvent('input', {
216+
bubbles: true,
217+
cancelable: false,
218+
data: value,
219+
inputType: 'insertText',
220+
});
221+
222+
this.#editable.dispatchEvent(inputEvent);
223+
209224
this.setText(value, undefined, runOnChange)
210225
this.#editable.blur();
211226
this.#editable.removeAttribute('contenteditable')
212227
}
213228

214-
else this.setText(value, undefined, runOnChange) // Ensure value is still set
229+
230+
else this.setText(value, undefined, runOnChange) // Just set value
215231
}
216232

217233
#render(property: 'renderer' | 'editor') {

tests/e2e/workflow.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ export default async function runWorkflow(name, workflow, identifier) {
379379
const page = dashboard.page
380380
const firstSessionForm = page.forms[0].form
381381
firstSessionForm.accordions["NWBFile"].toggle(true)
382-
window.getSelection().empty() // Remove annoying user-select highlight
383382
})
384383

385384
await takeScreenshot(join(identifier, 'metadata-nwbfile'), 100)

0 commit comments

Comments
 (0)