Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@

let list: List

const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => {
if (dir === 'vertical') {
// Select next
list?.select(offset, of)
const listProvider = new ListSelectionProvider(
(offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection, noScroll?: boolean) => {
if (dir === 'vertical') {
// Select next
list?.select(offset, of, noScroll)
}
}
})
)
let docs: Doc[] = []
function select () {
listProvider.update(docs)
Expand Down
10 changes: 8 additions & 2 deletions plugins/view-resources/src/actionImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,16 @@ contextStore.subscribe((it) => {
$contextStore = it
})

export function select (evt: Event | undefined, offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection): void {
export function select (
evt: Event | undefined,
offset: 1 | -1 | 0,
of?: Doc,
direction?: SelectDirection,
noScroll?: boolean
): void {
closeTooltip()
if ($focusStore.provider?.select !== undefined) {
$focusStore.provider?.select(offset, of, direction)
$focusStore.provider?.select(offset, of, direction, noScroll)
evt?.preventDefault()
previewDocument.update((old) => {
if (old !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/view-resources/src/components/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
dispatch('row-focus', object)
}

export function select (offset: 1 | -1 | 0, of?: Doc): void {
export function select (offset: 1 | -1 | 0, of?: Doc, noScroll?: boolean): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad name for field, in case false is passed it will scroll

image

let pos = (of !== undefined ? objects.findIndex((it) => it._id === of._id) : selection) ?? -1
pos += offset
if (pos < 0) {
Expand All @@ -182,7 +182,7 @@
const r = refs[pos]
selection = pos
onRow(objects[pos])
if (r !== undefined) {
if (r !== undefined && !noScroll) {
r?.scrollIntoView({ behavior: 'auto', block: 'nearest' })
}
}
Expand Down
12 changes: 7 additions & 5 deletions plugins/view-resources/src/components/TableBrowser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
export let loadingProps: LoadingProps | undefined = undefined

let table: Table
const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => {
if (dir === 'vertical') {
// Select next
table?.select(offset, of)
const listProvider = new ListSelectionProvider(
(offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection, noScroll?: boolean) => {
if (dir === 'vertical') {
// Select next
table?.select(offset, of, noScroll)
}
}
})
)

onMount(() => {
;(document.activeElement as HTMLElement)?.blur()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
}

$: select(undefined, 0, element, 'vertical')
$: select(undefined, 0, element, 'vertical', true)
</script>

{#if $focusStore.focus !== undefined && $focusStore.provider !== undefined}
Expand Down
4 changes: 2 additions & 2 deletions plugins/view-resources/src/components/list/List.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
selectedObjectIds = []
}

export function select (offset: 2 | -2 | 1 | -1 | 0, of?: Doc): void {
export function select (offset: 2 | -2 | 1 | -1 | 0, of?: Doc, noScroll?: boolean): void {
if (of !== undefined || offset !== 0) {
listCategories?.select(offset, of)
listCategories?.select(offset, of, undefined, noScroll)
}
}

Expand Down
15 changes: 10 additions & 5 deletions plugins/view-resources/src/components/list/ListCategories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@
return -1
}

export function select (offset: 2 | 1 | -2 | -1 | 0, of?: Doc, dir?: 'vertical' | 'horizontal'): void {
export function select (
offset: 2 | 1 | -2 | -1 | 0,
of?: Doc,
dir?: 'vertical' | 'horizontal',
noScroll?: boolean
): void {
let pos = (of != null ? docs.findIndex((it) => it._id === of._id) : selection) ?? -1
if (pos === -1) {
for (const st of categories) {
Expand Down Expand Up @@ -276,7 +281,7 @@
} else {
const obj = stateObjs[statePos - 1]
if (obj !== undefined) {
scrollInto(objState, obj)
if (!noScroll) scrollInto(objState, obj)
dispatch('row-focus', obj)
}
}
Expand All @@ -296,19 +301,19 @@
} else {
const obj = stateObjs[statePos + 1]
if (obj !== undefined) {
scrollInto(objState, obj)
if (!noScroll) scrollInto(objState, obj)
dispatch('row-focus', obj)
}
}
return
}
}
if (offset === 0) {
scrollInto(objState, obj)
if (!noScroll) scrollInto(objState, obj)
dispatch('row-focus', obj)
}
} else {
listCategory[objState]?.select(offset, of, dir)
listCategory[objState]?.select(offset, of, dir, noScroll)
}
}
function scrollInto (statePos: number, obj: Doc): void {
Expand Down
12 changes: 7 additions & 5 deletions plugins/view-resources/src/components/list/ListView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
let divScroll: HTMLDivElement
let listWidth: number

const listProvider = new ListSelectionProvider((offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection) => {
if (dir === 'vertical') {
// Select next
list?.select(offset, of)
const listProvider = new ListSelectionProvider(
(offset: 1 | -1 | 0, of?: Doc, dir?: SelectDirection, noScroll?: boolean) => {
if (dir === 'vertical') {
// Select next
list?.select(offset, of, noScroll)
}
}
})
)

onMount(() => {
;(document.activeElement as HTMLElement)?.blur()
Expand Down
11 changes: 6 additions & 5 deletions plugins/view-resources/src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface SelectionFocusProvider {
// * If vertical, next will return item under.
// * If horizontal, next will return item on right.
// of - document offset from we requesting.
select?: (offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection) => void
select?: (offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection, noScroll?: boolean) => void

// Update documents content
update: (docs: Doc[]) => void
Expand Down Expand Up @@ -110,7 +110,7 @@ export class ListSelectionProvider implements SelectionFocusProvider {
_current?: FocusSelection
private readonly unsubscribe: Unsubscriber
constructor (
private readonly delegate: (offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection) => void,
private readonly delegate: (offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection, noScroll?: boolean) => void,
autoDestroy = true
) {
this.unsubscribe = focusStore.subscribe((doc) => {
Expand Down Expand Up @@ -154,10 +154,11 @@ export class ListSelectionProvider implements SelectionFocusProvider {
this.unsubscribe()
}

select (offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection): void {
this.delegate(offset, of, direction)
select (offset: 1 | -1 | 0, of?: Doc, direction?: SelectDirection, noScroll?: boolean): void {
this.delegate(offset, of, direction, noScroll)
}

// this is the main method that is called when docs are updated
update (docs: Doc[]): void {
this._docs = docs

Expand All @@ -171,7 +172,7 @@ export class ListSelectionProvider implements SelectionFocusProvider {
this.delegate(0, undefined, 'vertical')
} else {
// Check if we don't have object, we need to select first one.
this.delegate(0, this._current?.focus, 'vertical')
this.delegate(0, this._current?.focus, 'vertical', true)
}
if (this._current?.focus === undefined) {
updateFocus({ focus: this._current?.focus, provider: this })
Expand Down