Autoselect for ShareDialog

This commit is contained in:
Moritz Dieing 2021-03-07 13:03:35 +01:00
parent 24feec3bc4
commit e06041bfcb
2 changed files with 16 additions and 0 deletions

View File

@ -0,0 +1,12 @@
window.autoSelect = (className) => {
let el = document.getElementsByClassName(className);
Array.from(el).forEach(field => {
field.addEventListener('focus', event => {
let e = event.target.shadowRoot.querySelector('input');
if (!e) {
e = event.target.shadowRoot.querySelector('textArea');
}
e.setSelectionRange(0, e.value.length);
});
});
}

View File

@ -1,6 +1,8 @@
package edu.kit.typicalc.view.content.typeinferencecontent;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.icon.Icon;
@ -15,6 +17,7 @@ import com.vaadin.flow.i18n.LocaleChangeObserver;
/**
* Contains GUI elements to extract the URL and LaTeX code of the currently shown proof tree.
*/
@JsModule("./src/share-dialog-autoselect.js")
@CssImport("./styles/view/share-dialog.css")
public class ShareDialog extends Dialog implements LocaleChangeObserver {
@ -62,6 +65,7 @@ public class ShareDialog extends Dialog implements LocaleChangeObserver {
packageArea.setClassName(FIELD_CLASS);
latexArea.setValue(latexCode);
latexArea.setClassName(FIELD_CLASS);
UI.getCurrent().getPage().executeJs("window.autoSelect($0)", FIELD_CLASS);
layout.add(urlField, packageArea, latexArea);