Fix height jumping when switching from empty to non-empty and vice versa

This commit is contained in:
josdejong 2020-05-13 20:33:43 +02:00
parent 5cc3665c47
commit 0da297c5d3
1 changed files with 25 additions and 8 deletions

View File

@ -52,18 +52,14 @@
$: valueIsUrl = isUrl(value) $: valueIsUrl = isUrl(value)
$: keyClass = classnames('key', { let keyClass
empty: key === '', $: keyClass = getKeyClass(key, searchResult)
search: searchResult
? !!searchResult[SEARCH_PROPERTY]
: false
})
let valueClass let valueClass
$: valueClass = getValueClass(value, searchResult) $: valueClass = getValueClass(value, searchResult)
$: if (domKey) { $: if (domKey) {
if (document.activeElement !== domKey || key === '') { if (document.activeElement !== domKey) {
// synchronize the innerText of the editable div with the escaped value, // synchronize the innerText of the editable div with the escaped value,
// but only when the domValue does not have focus else we will ruin // but only when the domValue does not have focus else we will ruin
// the cursor position. // the cursor position.
@ -72,7 +68,7 @@
} }
$: if (domValue) { $: if (domValue) {
if (document.activeElement !== domValue || value === '') { if (document.activeElement !== domValue) {
// synchronize the innerText of the editable div with the escaped value, // synchronize the innerText of the editable div with the escaped value,
// but only when the domValue does not have focus else we will ruin // but only when the domValue does not have focus else we will ruin
// the cursor position. // the cursor position.
@ -92,6 +88,15 @@
}) })
} }
function getKeyClass(key, searchResult) {
return classnames('key', {
empty: key === '',
search: searchResult
? !!searchResult[SEARCH_PROPERTY]
: false
})
}
function toggle () { function toggle () {
expanded = !expanded expanded = !expanded
} }
@ -113,6 +118,14 @@
const updateKeyDebounced = debounce(updateKey, DEBOUNCE_DELAY) const updateKeyDebounced = debounce(updateKey, DEBOUNCE_DELAY)
function handleKeyInput (event) { function handleKeyInput (event) {
const newKey = getPlainText(event.target)
keyClass = getKeyClass(newKey, searchResult)
if (newKey === '') {
// immediately update to cleanup any left over <br/>
setPlainText(domKey, '')
}
// fire a change event only after a delay
updateKeyDebounced() updateKeyDebounced()
} }
@ -145,6 +158,10 @@
// do not await the debounced update to apply styles // do not await the debounced update to apply styles
const newValue = getValue() const newValue = getValue()
valueClass = getValueClass(newValue, searchResult) valueClass = getValueClass(newValue, searchResult)
if (newValue === '') {
// immediately update to cleanup any left over <br/>
setPlainText(domValue, '')
}
// fire a change event only after a delay // fire a change event only after a delay
debouncedUpdateValue() debouncedUpdateValue()