mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 03:32:36 +02:00
Add format_text
command, and editor.marks
state (#3308)
* add format_text command, refactor command extensions * update onChange to not receive selection * update docs * fix tests
This commit is contained in:
@@ -16,24 +16,14 @@ export const HistoryCommand = {
|
||||
*/
|
||||
|
||||
isHistoryCommand(value: any): value is HistoryCommand {
|
||||
return (
|
||||
HistoryCommand.isRedoCommand(value) || HistoryCommand.isUndoCommand(value)
|
||||
)
|
||||
},
|
||||
if (Command.isCommand(value)) {
|
||||
switch (value.type) {
|
||||
case 'redo':
|
||||
case 'undo':
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a value is a `RedoCommand` object.
|
||||
*/
|
||||
|
||||
isRedoCommand(value: any): value is RedoCommand {
|
||||
return Command.isCommand(value) && value.type === 'redo'
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a value is an `UndoCommand` object.
|
||||
*/
|
||||
|
||||
isUndoCommand(value: any): value is UndoCommand {
|
||||
return Command.isCommand(value) && value.type === 'undo'
|
||||
return false
|
||||
},
|
||||
}
|
||||
|
@@ -13,11 +13,14 @@ export const withHistory = (editor: Editor): HistoryEditor => {
|
||||
editor.history = { undos: [], redos: [] }
|
||||
|
||||
editor.exec = (command: Command) => {
|
||||
if (HistoryEditor.isHistoryEditor(editor)) {
|
||||
if (
|
||||
HistoryEditor.isHistoryEditor(editor) &&
|
||||
HistoryCommand.isHistoryCommand(command)
|
||||
) {
|
||||
const { history } = editor
|
||||
const { undos, redos } = history
|
||||
|
||||
if (redos.length > 0 && HistoryCommand.isRedoCommand(command)) {
|
||||
if (command.type === 'redo' && redos.length > 0) {
|
||||
const batch = redos[redos.length - 1]
|
||||
|
||||
HistoryEditor.withoutSaving(editor, () => {
|
||||
@@ -33,7 +36,7 @@ export const withHistory = (editor: Editor): HistoryEditor => {
|
||||
return
|
||||
}
|
||||
|
||||
if (undos.length > 0 && HistoryCommand.isUndoCommand(command)) {
|
||||
if (command.type === 'undo' && undos.length > 0) {
|
||||
const batch = undos[undos.length - 1]
|
||||
|
||||
HistoryEditor.withoutSaving(editor, () => {
|
||||
|
Reference in New Issue
Block a user