Commit 95efe1f 1 parent 7ac6cf7 commit 95efe1f Copy full SHA for 95efe1f
File tree 4 files changed +20
-31
lines changed
packages/core/src/composables
4 files changed +20
-31
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,7 @@ The following 4 composable can be used to **get and set** the selections of edit
124
124
- ` reactive::useNotebookEditorSelections ` - All selections in the notebook editor.
125
125
- ` reactive::useNotebookEditorSelection ` - The primary selection in the notebook editor.
126
126
127
- See their docs for more information.
127
+ See their docs for more information. Note that ` reactive::useTextEditorSelections ` and ` reactive::useTextEditorSelection ` also support an ` acceptKind ` option to filter the change kind which has triggered this event (See ` vscode::TextEditorSelectionChangeKind ` ).
128
128
129
129
## Editor Viewport
130
130
Original file line number Diff line number Diff line change 1
1
import type { NotebookEditor } from 'vscode'
2
- import { window } from 'vscode'
3
- import { computed , shallowRef } from '../reactivity'
2
+ import { computed } from '../reactivity'
4
3
import { createKeyedComposable } from '../utils'
5
- import { useDisposable } from './useDisposable '
4
+ import { useNotebookEditorSelections } from './useNotebookEditorSelections '
6
5
7
6
/**
8
7
* @reactive `NotebookEditor.selection`
9
8
* @category editor
10
9
*/
11
10
export const useNotebookEditorSelection = createKeyedComposable (
12
11
( notebookEditor : NotebookEditor ) => {
13
- const selection = shallowRef ( notebookEditor . selection )
14
-
15
- useDisposable ( window . onDidChangeNotebookEditorSelection ( ( ev ) => {
16
- if ( ev . notebookEditor === notebookEditor )
17
- selection . value = ev . selections [ 0 ]
18
- } ) )
12
+ const selections = useNotebookEditorSelections ( notebookEditor )
19
13
20
14
return computed ( {
21
15
get ( ) {
22
- return selection . value
16
+ return selections . value [ 0 ]
23
17
} ,
24
18
set ( newSelection ) {
25
- selection . value = newSelection
26
- notebookEditor . selection = newSelection
19
+ selections . value = selections . value . toSpliced ( 0 , 1 , newSelection )
27
20
} ,
28
21
} )
29
22
} ,
Original file line number Diff line number Diff line change 1
- import type { TextEditor } from 'vscode'
2
- import { window } from 'vscode '
3
- import { computed , shallowRef } from '../reactivity'
1
+ import type { TextEditor , TextEditorSelectionChangeKind } from 'vscode'
2
+ import type { MaybeRefOrGetter } from '../reactivity '
3
+ import { computed } from '../reactivity'
4
4
import { createKeyedComposable } from '../utils'
5
- import { useDisposable } from './useDisposable '
5
+ import { useTextEditorSelections } from './useTextEditorSelections '
6
6
7
7
/**
8
8
* @reactive `TextEditor.selection`
9
9
* @category editor
10
10
*/
11
11
export const useTextEditorSelection = createKeyedComposable (
12
- ( textEditor : TextEditor ) => {
13
- const selection = shallowRef ( textEditor . selection )
14
-
15
- useDisposable ( window . onDidChangeTextEditorSelection ( ( ev ) => {
16
- if ( ev . textEditor === textEditor )
17
- selection . value = ev . selections [ 0 ]
18
- } ) )
12
+ ( textEditor : TextEditor , acceptKind ?: MaybeRefOrGetter < ( TextEditorSelectionChangeKind | undefined ) [ ] > ) => {
13
+ const selections = useTextEditorSelections ( textEditor , acceptKind )
19
14
20
15
return computed ( {
21
16
get ( ) {
22
- return selection . value
17
+ return selections . value [ 0 ]
23
18
} ,
24
19
set ( newSelection ) {
25
- selection . value = newSelection
26
- textEditor . selection = newSelection
20
+ selections . value = selections . value . toSpliced ( 0 , 1 , newSelection )
27
21
} ,
28
22
} )
29
23
} ,
Original file line number Diff line number Diff line change 1
- import type { TextEditor } from 'vscode'
1
+ import type { TextEditor , TextEditorSelectionChangeKind } from 'vscode'
2
2
import { window } from 'vscode'
3
- import { computed , shallowRef } from '../reactivity'
3
+ import type { MaybeRefOrGetter } from '../reactivity'
4
+ import { computed , shallowRef , toValue } from '../reactivity'
4
5
import { createKeyedComposable } from '../utils'
5
6
import { useDisposable } from './useDisposable'
6
7
@@ -9,11 +10,12 @@ import { useDisposable } from './useDisposable'
9
10
* @category editor
10
11
*/
11
12
export const useTextEditorSelections = createKeyedComposable (
12
- ( textEditor : TextEditor ) => {
13
+ ( textEditor : TextEditor , acceptKind ?: MaybeRefOrGetter < ( TextEditorSelectionChangeKind | undefined ) [ ] > ) => {
13
14
const selections = shallowRef ( textEditor . selections )
14
15
15
16
useDisposable ( window . onDidChangeTextEditorSelection ( ( ev ) => {
16
- if ( ev . textEditor === textEditor )
17
+ const kinds = toValue ( acceptKind )
18
+ if ( ev . textEditor === textEditor && ( ! kinds || kinds . includes ( ev . kind ) ) )
17
19
selections . value = ev . selections
18
20
} ) )
19
21
You can’t perform that action at this time.
0 commit comments