-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blocks): optimize the experience of switching selected blocks us…
…ing ArrowUp and ArrowDown (#6489)
- Loading branch information
Showing
7 changed files
with
300 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/blocks/src/note-block/commands/focus-block-end.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Command } from '@blocksuite/block-std'; | ||
|
||
export const focusBlockEnd: Command<'focusBlock'> = (ctx, next) => { | ||
const { focusBlock, std } = ctx; | ||
if (!focusBlock || !focusBlock.model.text) return; | ||
|
||
const { selection } = std; | ||
|
||
selection.setGroup('note', [ | ||
selection.create('text', { | ||
from: { | ||
path: focusBlock.path, | ||
index: focusBlock.model.text.length, | ||
length: 0, | ||
}, | ||
to: null, | ||
}), | ||
]); | ||
|
||
return next(); | ||
}; | ||
|
||
declare global { | ||
namespace BlockSuite { | ||
interface Commands { | ||
focusBlockEnd: typeof focusBlockEnd; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/blocks/src/note-block/commands/focus-block-start.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { Command } from '@blocksuite/block-std'; | ||
|
||
export const focusBlockStart: Command<'focusBlock'> = (ctx, next) => { | ||
const { focusBlock, std } = ctx; | ||
if (!focusBlock || !focusBlock.model.text) return; | ||
|
||
const { selection } = std; | ||
|
||
selection.setGroup('note', [ | ||
selection.create('text', { | ||
from: { path: focusBlock.path, index: 0, length: 0 }, | ||
to: null, | ||
}), | ||
]); | ||
|
||
return next(); | ||
}; | ||
|
||
declare global { | ||
namespace BlockSuite { | ||
interface Commands { | ||
focusBlockStart: typeof focusBlockStart; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.