Skip to content

Commit

Permalink
feat(editor): cursor in new delete entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Nov 7, 2021
1 parent e591e98 commit 6a8fe9b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
22 changes: 21 additions & 1 deletion src/components/editor/entity/EditorEntityShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
const edit = ref<boolean>(false)
const keyboard = ref<boolean>(false)
const commands = ref<boolean>(false)
const old_raw = ref<number>(props.entity.raw.length)
const data = ref<string>('')
const input = ref<HTMLDivElement | null>(null)
Expand Down Expand Up @@ -246,6 +247,7 @@
keyboard: true,
selectionInitial: payload?.selectionInitial,
switch: payload?.switch,
cursor: payload?.cursor,
})
}
Expand All @@ -254,6 +256,7 @@
keyboard: true,
selectionInitial: payload?.selectionInitial,
switch: payload?.switch,
cursor: payload?.cursor,
})
}
})
Expand Down Expand Up @@ -385,6 +388,19 @@
edit.value = true
await nextTick
if (options?.cursor) {
// set cursor in max old content position
raw
.v2()
.caret()
.set(input.value as HTMLDivElement, old_raw.value)
// update old raw
old_raw.value = data.value.length
await nextTick
}
}
const onEnter = async () => {
Expand Down Expand Up @@ -577,7 +593,11 @@
await nextTick
emitter.emit('entity-open', { entity: props.entity, up: true })
emitter.emit('entity-open', {
entity: props.entity,
up: true,
cursor: true,
})
} else if (e.key === 'ArrowUp') {
// to top
if (start) {
Expand Down
1 change: 1 addition & 0 deletions src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface EntityShowEditOptions {
keyboard?: boolean
switch?: boolean
selectionInitial?: boolean
cursor?: boolean
}

export interface EntityExternal {
Expand Down
1 change: 1 addition & 0 deletions src/types/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface VueEmitterEntityOpen {
up?: boolean
selectionInitial?: boolean
switch?: boolean
cursor?: boolean
}

export type VueEmitterName =
Expand Down
5 changes: 2 additions & 3 deletions src/use/pdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,8 @@ export const usePDF = () => {
set[s] = PDF.normalize[s]
})

if (PDF.normalize['Roboto']) set['Roboto'] = PDF.normalize['Roboto']

(pdfMake as any).fonts = set
if (PDF.normalize['Roboto'])
set['Roboto'] = PDF.normalize['Roboto'](pdfMake as any).fonts = set
}

const create = (): void => {
Expand Down
38 changes: 37 additions & 1 deletion src/use/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ID } from '../types/utils'
export const useScroll = () => {
const force = (tag: string) => {
setTimeout(() => {
Expand All @@ -24,5 +25,40 @@ export const useScroll = () => {
;(scr as HTMLElement).scrollIntoView()
}

return { force, to }
const entity = (id: ID<number>, display?: 'center' | 'top' | 'bottom') => {
const scr = document.querySelector(`#entity-${id}`)
if (display === 'center') {
;(scr as HTMLElement).scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'center',
})

return
}

if (display === 'bottom') {
;(scr as HTMLElement).scrollIntoView({
behavior: 'auto',
block: 'end',
inline: 'end',
})

return
}

if (display === 'top') {
;(scr as HTMLElement).scrollIntoView({
behavior: 'auto',
block: 'start',
inline: 'start',
})

return
}

;(scr as HTMLElement).scrollIntoView()
}

return { force, entity, to }
}

0 comments on commit 6a8fe9b

Please sign in to comment.