Skip to content

Commit

Permalink
UBER-872: StyleTextEditor: No update when change text in another text
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Karmatskikh <[email protected]>
  • Loading branch information
mixerka committed Sep 15, 2023
1 parent d3183a2 commit 3f9e651
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
5 changes: 4 additions & 1 deletion packages/text-editor/src/components/StyledTextBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
$: if (oldContent !== content) {
oldContent = content
rawValue = content
if (rawValue !== content) {
rawValue = content
textEditor?.setContent(content)
}
modified = false
}
$: if (!modified && rawValue !== content) modified = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
-->
<script lang="ts">
import { Class, Doc, Ref, updateAttribute } from '@hcengineering/core'
import { Doc, updateAttribute } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
import { createQuery, getAttribute, getClient, KeyedAttribute } from '@hcengineering/presentation'
Expand All @@ -27,27 +27,27 @@
export let key: KeyedAttribute
export let placeholder: IntlString
export let focusIndex = -1
let _id: Ref<Doc> | undefined = undefined
let _class: Ref<Class<Doc>> | undefined = undefined
const client = getClient()
const queryClient = createQuery()
let description = ''
let description: string
let haveUnsavedChanges = false
let doc: Doc | undefined
function checkForNewObject (object: Doc) {
if (object._id !== _id) return true
if (object._class !== _class) return true
return false
$: if (description === undefined) {
description = getAttribute(client, object, key)
}
// We need to query the document one more time
// To make a difference between update of description from the bottom
// And update to if from another tab.
$: object &&
queryClient.query(object._class, { _id: object._id }, async (result) => {
;[doc] = result
if (doc && checkForNewObject(object)) {
_class = object._class
_id = object._id
description = getAttribute(client, object, key)
queryClient.query(object._class, { _id: object._id }, async (result: Doc[]) => {
if (result.length > 0) {
if (!haveUnsavedChanges) {
const doc = result[0]
description = getAttribute(client, doc, key)
}
}
})
Expand All @@ -64,6 +64,7 @@
const old = getAttribute(client, object, key)
if (description !== old) {
await updateAttribute(client, object, object._class, key, description)
haveUnsavedChanges = false
dispatch('saved', true)
setTimeout(() => {
dispatch('saved', false)
Expand All @@ -75,6 +76,7 @@
let saveTrigger: any
function triggerSave (): void {
haveUnsavedChanges = true
clearTimeout(saveTrigger)
saveTrigger = setTimeout(save, 2500)
}
Expand All @@ -84,7 +86,7 @@
}
</script>

{#key doc?._id}
{#key object?._id}
<AttachmentStyledBox
{focusIndex}
enableBackReferences={true}
Expand Down

0 comments on commit 3f9e651

Please sign in to comment.