-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
224 additions
and
247 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
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
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
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,67 @@ | ||
import type { Command } from '@blocksuite/block-std'; | ||
|
||
export const dedentBlocks: Command< | ||
never, | ||
never, | ||
{ | ||
blockIds?: string[]; | ||
stopCapture?: boolean; | ||
} | ||
> = (ctx, next) => { | ||
let { blockIds } = ctx; | ||
const { std, stopCapture = true } = ctx; | ||
const { doc, selection, range, host } = std; | ||
const { schema } = doc; | ||
|
||
if (!blockIds || !blockIds.length) { | ||
const nativeRange = range.value; | ||
if (nativeRange) { | ||
const topBlocks = range.getSelectedBlockComponentsByRange(nativeRange, { | ||
match: el => el.model.role === 'content', | ||
mode: 'highest', | ||
}); | ||
if (topBlocks.length > 0) { | ||
blockIds = topBlocks.map(block => block.blockId); | ||
} | ||
} else { | ||
blockIds = std.selection.getGroup('note').map(sel => sel.blockId); | ||
} | ||
} | ||
|
||
if (!blockIds || !blockIds.length || doc.readonly) return; | ||
|
||
// Find the first model that can be unindented | ||
let firstDedentIndex = -1; | ||
for (let i = 0; i < blockIds.length; i++) { | ||
const model = doc.getBlock(blockIds[i])?.model; | ||
if (!model) continue; | ||
const parent = doc.getParent(blockIds[i]); | ||
if (!parent) continue; | ||
const grandParent = doc.getParent(parent); | ||
if (!grandParent) continue; | ||
|
||
if (schema.isValid(model.flavour, grandParent.flavour)) { | ||
firstDedentIndex = i; | ||
break; | ||
} | ||
} | ||
|
||
if (firstDedentIndex === -1) return; | ||
|
||
if (stopCapture) doc.captureSync(); | ||
const dedentIds = blockIds.slice(firstDedentIndex); | ||
dedentIds.forEach(id => { | ||
std.command.exec('dedentBlock', { blockId: id, stopCapture: false }); | ||
}); | ||
|
||
const textSelection = selection.find('text'); | ||
if (textSelection) { | ||
host.updateComplete | ||
.then(() => { | ||
range.syncTextSelectionToRange(textSelection); | ||
}) | ||
.catch(console.error); | ||
} | ||
|
||
return next(); | ||
}; |
This file was deleted.
Oops, something went wrong.
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.