Skip to content

Commit c6eece6

Browse files
refact: Clean up methods
1 parent c5cc8f1 commit c6eece6

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

panel/src/components/Forms/Input/TextareaInput.vue

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ export default {
100100
url: this.$panel.urls.api + "/" + this.endpoints.field + "/upload",
101101
multiple: false,
102102
on: {
103-
cancel: async () => {
104-
await this.restoreSelection(selectionRange);
105-
},
103+
cancel: async () => await this.restoreSelection(selectionRange),
106104
done: async (files) => {
107105
await this.restoreSelection(selectionRange);
108106
await this.insertUpload(files);
@@ -131,24 +129,25 @@ export default {
131129
},
132130
methods: {
133131
dialog(dialog) {
134-
const restoreSelection = this.restoreSelectionCallback();
132+
const selectionRange = this.selectionRange();
135133
136134
this.$panel.dialog.open({
137135
component: "k-toolbar-" + dialog + "-dialog",
138136
props: {
139137
value: this.parseSelection()
140138
},
141139
on: {
142-
cancel: restoreSelection,
143-
submit: (text) => {
140+
cancel: async () => await this.restoreSelection(selectionRange),
141+
submit: async (text) => {
144142
this.$panel.dialog.close();
145-
restoreSelection(() => this.insert(text));
143+
await this.restoreSelection(selectionRange);
144+
await this.insert(text);
146145
}
147146
}
148147
});
149148
},
150149
file() {
151-
const restoreSelection = this.restoreSelectionCallback();
150+
const selectionRange = this.selectionRange();
152151
153152
this.$panel.dialog.open({
154153
component: "k-files-dialog",
@@ -157,9 +156,10 @@ export default {
157156
multiple: false
158157
},
159158
on: {
160-
cancel: restoreSelection,
161-
submit: (file) => {
162-
restoreSelection(() => this.insertFile(file));
159+
cancel: async () => await this.restoreSelection(selectionRange),
160+
submit: async (file) => {
161+
await this.restoreSelection(selectionRange);
162+
await this.insertFile(file);
163163
this.$panel.dialog.close();
164164
}
165165
}
@@ -176,9 +176,7 @@ export default {
176176
text = text(this.$refs.input, this.selection());
177177
}
178178
179-
await this.$nextTick();
180-
181-
input.focus();
179+
this.focus();
182180
183181
// try first via execCommand as this will be considered
184182
// as a user action and can be undone by the browser's
@@ -300,14 +298,16 @@ export default {
300298
title: selection
301299
};
302300
},
303-
prepend(text) {
304-
this.insert(text + " " + this.selection());
301+
async prepend(text) {
302+
await this.insert(text + " " + this.selection());
305303
},
306304
async restoreSelection({ start, end }) {
307305
this.$refs.input.setSelectionRange(start, end);
308-
309306
return this.$nextTick();
310307
},
308+
/**
309+
* @deprecated 5.0.0 Use `restoreSelection` instead
310+
*/
311311
restoreSelectionCallback() {
312312
// store selection
313313
const selectionRange = this.selectionRange();

0 commit comments

Comments
 (0)