Skip to content

Commit

Permalink
Merge pull request #741 from NeurodataWithoutBorders/clear-selections…
Browse files Browse the repository at this point in the history
…-when-transitioning

Avoid needless selections and clear on transition
  • Loading branch information
CodyCBakerPhD authored Apr 11, 2024
2 parents 3a1e8e6 + 290f16d commit f0a5de8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/renderer/src/stories/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export class Dashboard extends LitElement {
}

setMain(page) {
window.getSelection().empty(); // Remove user selection before transitioning

// Update Previous Page
const info = page.info;
const previous = this.page;
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/src/stories/table/Cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ export class TableCell extends LitElement {
else if (this.schema.format === "date-time") {
cls = DateTimeCell
this.type = "date-time"
} else if (this.schema.type === "object") {
}

else if (this.schema.type === "object") {
cls = NestedInputCell
this.type = "table"
}
Expand Down
24 changes: 20 additions & 4 deletions src/renderer/src/stories/table/cells/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,33 @@ export class TableCellBase extends LitElement {

set(value: any, runOnChange = true) {

if (document.execCommand) {
// Ensure all operations are undoable
if (typeof InputEvent === 'function') {
this.#editable.setAttribute('contenteditable', '')
this.#editable.focus();
document.execCommand('selectAll');
document.execCommand('insertText', false, value);

const range = document.createRange();
range.selectNodeContents(this.#editable);
const sel = window.getSelection()!;
sel.removeAllRanges();
sel.addRange(range);

const inputEvent = new InputEvent('input', {
bubbles: true,
cancelable: false,
data: value,
inputType: 'insertText',
});

this.#editable.dispatchEvent(inputEvent);

this.setText(value, undefined, runOnChange)
this.#editable.blur();
this.#editable.removeAttribute('contenteditable')
}

else this.setText(value, undefined, runOnChange) // Ensure value is still set

else this.setText(value, undefined, runOnChange) // Just set value
}

#render(property: 'renderer' | 'editor') {
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ export default async function runWorkflow(name, workflow, identifier) {
const page = dashboard.page
const firstSessionForm = page.forms[0].form
firstSessionForm.accordions["NWBFile"].toggle(true)
window.getSelection().empty() // Remove annoying user-select highlight
})

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

0 comments on commit f0a5de8

Please sign in to comment.