livebook/assets/js/focus_on_update/index.js
Jonatan Kłosko f0606b109d
Automatically back up notebooks without a file (#736)
* Improve file select layout on long paths

* Automatically back up notebooks without a file

* Run formatter

* Add margin when there are no sections

* Add an informative note about autosave directory

* Store autosave path instead of file in the config

* Rename autosave dir to autosave path

* Fix insert mode escape on section headlines

* Show ellipsis on selected file too

* Always create the default directory

* Apply review comments
2021-12-04 16:29:14 +01:00

28 lines
552 B
JavaScript

import { isEditableElement } from "../lib/utils";
/**
* A hook used to focus an element whenever it receives LV update.
*/
const FocusOnUpdate = {
mounted() {
this.__focus();
},
updated() {
if (this.el !== document.activeElement) {
this.__focus();
}
},
__focus() {
if (isEditableElement(document.activeElement)) {
return;
}
this.el.focus();
this.el.selectionStart = this.el.selectionEnd = this.el.value.length;
this.el.scrollLeft = this.el.scrollWidth;
},
};
export default FocusOnUpdate;