Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Selection #709

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions html/js/routes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ routes.push({
this.$root.stopLoading();
},
edit(setting, nodeId) {
setTimeout(() => {
if (nodeId) {
if ((this.form.key == nodeId) || !this.cancel()) return;
this.form.key = nodeId;
Expand All @@ -523,6 +524,24 @@ routes.push({
this.form.value = setting.value;
this.$root.drawAttention('#setting-global-save');
}

// transfer caret position from non-edit element to edit element
let selector = nodeId ? 'node-value-output-' + nodeId : 'value-output';
const before = document.getElementById(selector);
const scrollTop = before?.scrollTop || 0;
const selStart = before?.selectionStart || 0;
const selEnd = before?.selectionEnd || 0;
this.$nextTick(() => {
selector = nodeId ? 'node-value-input-' + nodeId : 'value-input';
const after = document.getElementById(selector);
if (after && typeof scrollTop !== 'undefined' &&
typeof selStart !== 'undefined' && typeof selEnd !== 'undefined') {
after.focus();
after.scrollTop = scrollTop;
after.setSelectionRange(selStart, selEnd);
}
});
}, 1);
},
addNode(setting, nodeId) {
if (this.cancel() && setting && nodeId) {
Expand Down
6 changes: 5 additions & 1 deletion html/js/routes/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,14 @@ test('saveRegexValidMultiline', async () => {
expect(mock).toHaveBeenCalledWith('config/', {"id": "test.id", "nodeId": null, "value": "123\n456"});
});

test('edit', () => {
test('edit', async () => {
// Global edit, nothing pending
setupSettings();
comp.cancelDialog = false;
comp.form.value = null;
comp.form.key = null;
comp.edit(comp.settings[0], null);
await new Promise(resolve => setTimeout(resolve, 2));
expect(comp.form.key).toBe("s-id");
expect(comp.form.value).toBe("orig-value");
expect(comp.cancelDialog).toBe(false);
Expand All @@ -526,6 +527,7 @@ test('edit', () => {
comp.form.key = "s-id2";
comp.activeBackup = ["s-id2"];
comp.edit(comp.settings[0], null);
await new Promise(resolve => setTimeout(resolve, 2));
expect(comp.form.key).toBe("s-id2");
expect(comp.form.value).toBe("touched-value");
expect(comp.cancelDialog).toBe(true);
Expand All @@ -535,6 +537,7 @@ test('edit', () => {
comp.form.value = null;
comp.form.key = null;
comp.edit(comp.settings[0], "n1");
await new Promise(resolve => setTimeout(resolve, 2));
expect(comp.form.key).toBe("n1");
expect(comp.form.value).toBe("123");
expect(comp.cancelDialog).toBe(false);
Expand All @@ -544,6 +547,7 @@ test('edit', () => {
comp.form.value = "touched-value";
comp.form.key = "n2";
comp.edit(comp.settings[0], "n1");
await new Promise(resolve => setTimeout(resolve, 2));
expect(comp.form.key).toBe("n2");
expect(comp.form.value).toBe("touched-value");
expect(comp.cancelDialog).toBe(true);
Expand Down
Loading