Skip to content

Commit

Permalink
feat: support customzing the record time
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Sep 14, 2023
1 parent 23a7d4e commit e11c5b6
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 34 deletions.
7 changes: 5 additions & 2 deletions lib/src/editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum TransactionTime {
class EditorState {
EditorState({
required this.document,
this.minHistoryItemDuration = const Duration(milliseconds: 200),
}) {
undoManager.state = this;
}
Expand All @@ -82,6 +83,9 @@ class EditorState {

final Document document;

// the minimum duration for saving the history item.
final Duration minHistoryItemDuration;

/// Whether the editor is editable.
bool editable = true;

Expand Down Expand Up @@ -477,8 +481,7 @@ class EditorState {
return;
}
_debouncedSealHistoryItemTimer?.cancel();
_debouncedSealHistoryItemTimer =
Timer(const Duration(milliseconds: 1000), () {
_debouncedSealHistoryItemTimer = Timer(minHistoryItemDuration, () {
if (undoManager.undoStack.isNonEmpty) {
Log.editor.debug('Seal history item');
final last = undoManager.undoStack.last;
Expand Down
96 changes: 80 additions & 16 deletions lib/src/l10n/intl/messages_zh-CN.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,85 @@ class MessageLookup extends MessageLookupByLibrary {

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"bold": MessageLookupByLibrary.simpleMessage(""),
"bulletedList": MessageLookupByLibrary.simpleMessage(""),
"checkbox": MessageLookupByLibrary.simpleMessage(""),
"embedCode": MessageLookupByLibrary.simpleMessage(""),
"heading1": MessageLookupByLibrary.simpleMessage(""),
"heading2": MessageLookupByLibrary.simpleMessage(""),
"heading3": MessageLookupByLibrary.simpleMessage(""),
"highlight": MessageLookupByLibrary.simpleMessage(""),
"image": MessageLookupByLibrary.simpleMessage(""),
"italic": MessageLookupByLibrary.simpleMessage(""),
"link": MessageLookupByLibrary.simpleMessage(""),
"numberedList": MessageLookupByLibrary.simpleMessage(""),
"quote": MessageLookupByLibrary.simpleMessage(""),
"strikethrough": MessageLookupByLibrary.simpleMessage(""),
"text": MessageLookupByLibrary.simpleMessage(""),
"underline": MessageLookupByLibrary.simpleMessage("")
"addYourLink": MessageLookupByLibrary.simpleMessage("添加链接"),
"auto": MessageLookupByLibrary.simpleMessage("自动"),
"backgroundColor": MessageLookupByLibrary.simpleMessage("背景颜色"),
"backgroundColorBlue": MessageLookupByLibrary.simpleMessage("蓝色背景"),
"backgroundColorBrown": MessageLookupByLibrary.simpleMessage("棕色背景"),
"backgroundColorDefault": MessageLookupByLibrary.simpleMessage("默认背景色"),
"backgroundColorGray": MessageLookupByLibrary.simpleMessage("灰色背景"),
"backgroundColorGreen": MessageLookupByLibrary.simpleMessage("绿色背景"),
"backgroundColorOrange": MessageLookupByLibrary.simpleMessage("橙色背景"),
"backgroundColorPink": MessageLookupByLibrary.simpleMessage("粉色背景"),
"backgroundColorPurple": MessageLookupByLibrary.simpleMessage("紫色背景"),
"backgroundColorRed": MessageLookupByLibrary.simpleMessage("红色背景"),
"backgroundColorYellow": MessageLookupByLibrary.simpleMessage("黄色背景"),
"bold": MessageLookupByLibrary.simpleMessage("粗体"),
"bulletedList": MessageLookupByLibrary.simpleMessage("无序列表"),
"cancel": MessageLookupByLibrary.simpleMessage("取消"),
"checkbox": MessageLookupByLibrary.simpleMessage("选框"),
"clearHighlightColor": MessageLookupByLibrary.simpleMessage("清除高亮颜色"),
"color": MessageLookupByLibrary.simpleMessage("颜色"),
"copyLink": MessageLookupByLibrary.simpleMessage("复制链接"),
"customColor": MessageLookupByLibrary.simpleMessage("自定义颜色"),
"done": MessageLookupByLibrary.simpleMessage("完成"),
"editLink": MessageLookupByLibrary.simpleMessage("修改链接"),
"embedCode": MessageLookupByLibrary.simpleMessage("代码块"),
"fontColorBlue": MessageLookupByLibrary.simpleMessage("蓝色"),
"fontColorBrown": MessageLookupByLibrary.simpleMessage("棕色"),
"fontColorDefault": MessageLookupByLibrary.simpleMessage("默认"),
"fontColorGray": MessageLookupByLibrary.simpleMessage("灰色"),
"fontColorGreen": MessageLookupByLibrary.simpleMessage("绿色"),
"fontColorOrange": MessageLookupByLibrary.simpleMessage("橙色"),
"fontColorPink": MessageLookupByLibrary.simpleMessage("粉红色"),
"fontColorPurple": MessageLookupByLibrary.simpleMessage("紫色"),
"fontColorRed": MessageLookupByLibrary.simpleMessage("红色"),
"fontColorYellow": MessageLookupByLibrary.simpleMessage("黄色"),
"heading1": MessageLookupByLibrary.simpleMessage("一级标题"),
"heading2": MessageLookupByLibrary.simpleMessage("二级标题"),
"heading3": MessageLookupByLibrary.simpleMessage("三级标题"),
"hexValue": MessageLookupByLibrary.simpleMessage("十六进制值"),
"highlight": MessageLookupByLibrary.simpleMessage("高亮"),
"highlightColor": MessageLookupByLibrary.simpleMessage("高亮颜色"),
"image": MessageLookupByLibrary.simpleMessage("图片"),
"italic": MessageLookupByLibrary.simpleMessage("斜体"),
"lightLightTint1": MessageLookupByLibrary.simpleMessage("紫色"),
"lightLightTint2": MessageLookupByLibrary.simpleMessage("粉红色"),
"lightLightTint3": MessageLookupByLibrary.simpleMessage("浅粉红色"),
"lightLightTint4": MessageLookupByLibrary.simpleMessage("橙色"),
"lightLightTint5": MessageLookupByLibrary.simpleMessage("黄色"),
"lightLightTint6": MessageLookupByLibrary.simpleMessage("草绿色"),
"lightLightTint7": MessageLookupByLibrary.simpleMessage("绿色"),
"lightLightTint8": MessageLookupByLibrary.simpleMessage("水蓝色"),
"lightLightTint9": MessageLookupByLibrary.simpleMessage("蓝色"),
"link": MessageLookupByLibrary.simpleMessage("链接"),
"linkAddressHint": MessageLookupByLibrary.simpleMessage("请输入URL"),
"linkText": MessageLookupByLibrary.simpleMessage("文字"),
"linkTextHint": MessageLookupByLibrary.simpleMessage("请输入文字"),
"ltr": MessageLookupByLibrary.simpleMessage("自左至右"),
"mobileHeading1": MessageLookupByLibrary.simpleMessage("一级标题"),
"mobileHeading2": MessageLookupByLibrary.simpleMessage("二级标题"),
"mobileHeading3": MessageLookupByLibrary.simpleMessage("三级标题"),
"numberedList": MessageLookupByLibrary.simpleMessage("有序列表"),
"opacity": MessageLookupByLibrary.simpleMessage("透明度"),
"openLink": MessageLookupByLibrary.simpleMessage("打开链接"),
"quote": MessageLookupByLibrary.simpleMessage("引文"),
"removeLink": MessageLookupByLibrary.simpleMessage("移除链接"),
"resetToDefaultColor": MessageLookupByLibrary.simpleMessage("重设为默认颜色"),
"rtl": MessageLookupByLibrary.simpleMessage("自右至左"),
"strikethrough": MessageLookupByLibrary.simpleMessage("删除线"),
"text": MessageLookupByLibrary.simpleMessage("文本"),
"textColor": MessageLookupByLibrary.simpleMessage("文字颜色"),
"tint1": MessageLookupByLibrary.simpleMessage("色调1"),
"tint2": MessageLookupByLibrary.simpleMessage("色调2"),
"tint3": MessageLookupByLibrary.simpleMessage("色调3"),
"tint4": MessageLookupByLibrary.simpleMessage("色调4"),
"tint5": MessageLookupByLibrary.simpleMessage("色调5"),
"tint6": MessageLookupByLibrary.simpleMessage("色调6"),
"tint7": MessageLookupByLibrary.simpleMessage("色调7"),
"tint8": MessageLookupByLibrary.simpleMessage("色调8"),
"tint9": MessageLookupByLibrary.simpleMessage("色调9"),
"underline": MessageLookupByLibrary.simpleMessage("下划线"),
"urlHint": MessageLookupByLibrary.simpleMessage("URL")
};
}
96 changes: 80 additions & 16 deletions lib/src/l10n/intl/messages_zh-TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,85 @@ class MessageLookup extends MessageLookupByLibrary {

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"bold": MessageLookupByLibrary.simpleMessage(""),
"bulletedList": MessageLookupByLibrary.simpleMessage(""),
"checkbox": MessageLookupByLibrary.simpleMessage(""),
"embedCode": MessageLookupByLibrary.simpleMessage(""),
"heading1": MessageLookupByLibrary.simpleMessage(""),
"heading2": MessageLookupByLibrary.simpleMessage(""),
"heading3": MessageLookupByLibrary.simpleMessage(""),
"highlight": MessageLookupByLibrary.simpleMessage(""),
"image": MessageLookupByLibrary.simpleMessage(""),
"italic": MessageLookupByLibrary.simpleMessage(""),
"link": MessageLookupByLibrary.simpleMessage(""),
"numberedList": MessageLookupByLibrary.simpleMessage(""),
"quote": MessageLookupByLibrary.simpleMessage(""),
"strikethrough": MessageLookupByLibrary.simpleMessage(""),
"text": MessageLookupByLibrary.simpleMessage(""),
"underline": MessageLookupByLibrary.simpleMessage("")
"addYourLink": MessageLookupByLibrary.simpleMessage("添加連結"),
"auto": MessageLookupByLibrary.simpleMessage("自動"),
"backgroundColor": MessageLookupByLibrary.simpleMessage("背景顏色"),
"backgroundColorBlue": MessageLookupByLibrary.simpleMessage("藍色背景"),
"backgroundColorBrown": MessageLookupByLibrary.simpleMessage("棕色背景"),
"backgroundColorDefault": MessageLookupByLibrary.simpleMessage("默認背景色"),
"backgroundColorGray": MessageLookupByLibrary.simpleMessage("灰色背景"),
"backgroundColorGreen": MessageLookupByLibrary.simpleMessage("綠色背景"),
"backgroundColorOrange": MessageLookupByLibrary.simpleMessage("橙色背景"),
"backgroundColorPink": MessageLookupByLibrary.simpleMessage("粉色背景"),
"backgroundColorPurple": MessageLookupByLibrary.simpleMessage("紫色背景"),
"backgroundColorRed": MessageLookupByLibrary.simpleMessage("紅色背景"),
"backgroundColorYellow": MessageLookupByLibrary.simpleMessage("黃色背景"),
"bold": MessageLookupByLibrary.simpleMessage("粗體"),
"bulletedList": MessageLookupByLibrary.simpleMessage("無序列表"),
"cancel": MessageLookupByLibrary.simpleMessage("取消"),
"checkbox": MessageLookupByLibrary.simpleMessage("核取方塊"),
"clearHighlightColor": MessageLookupByLibrary.simpleMessage("清除高亮顏色"),
"color": MessageLookupByLibrary.simpleMessage("顏色"),
"copyLink": MessageLookupByLibrary.simpleMessage("複製連結"),
"customColor": MessageLookupByLibrary.simpleMessage("自定義顏色"),
"done": MessageLookupByLibrary.simpleMessage("完成"),
"editLink": MessageLookupByLibrary.simpleMessage("修改連結"),
"embedCode": MessageLookupByLibrary.simpleMessage("代碼塊"),
"fontColorBlue": MessageLookupByLibrary.simpleMessage("藍色"),
"fontColorBrown": MessageLookupByLibrary.simpleMessage("棕色"),
"fontColorDefault": MessageLookupByLibrary.simpleMessage("默認"),
"fontColorGray": MessageLookupByLibrary.simpleMessage("灰色"),
"fontColorGreen": MessageLookupByLibrary.simpleMessage("綠色"),
"fontColorOrange": MessageLookupByLibrary.simpleMessage("橙色"),
"fontColorPink": MessageLookupByLibrary.simpleMessage("粉紅色"),
"fontColorPurple": MessageLookupByLibrary.simpleMessage("紫色"),
"fontColorRed": MessageLookupByLibrary.simpleMessage("紅色"),
"fontColorYellow": MessageLookupByLibrary.simpleMessage("黃色"),
"heading1": MessageLookupByLibrary.simpleMessage("一級標題"),
"heading2": MessageLookupByLibrary.simpleMessage("二級標題"),
"heading3": MessageLookupByLibrary.simpleMessage("三級標題"),
"hexValue": MessageLookupByLibrary.simpleMessage("十六進位值"),
"highlight": MessageLookupByLibrary.simpleMessage("高亮"),
"highlightColor": MessageLookupByLibrary.simpleMessage("高亮顏色"),
"image": MessageLookupByLibrary.simpleMessage("圖片"),
"italic": MessageLookupByLibrary.simpleMessage("斜體"),
"lightLightTint1": MessageLookupByLibrary.simpleMessage("紫色"),
"lightLightTint2": MessageLookupByLibrary.simpleMessage("粉紅色"),
"lightLightTint3": MessageLookupByLibrary.simpleMessage("淺粉紅色"),
"lightLightTint4": MessageLookupByLibrary.simpleMessage("橙色"),
"lightLightTint5": MessageLookupByLibrary.simpleMessage("黃色"),
"lightLightTint6": MessageLookupByLibrary.simpleMessage("草綠色"),
"lightLightTint7": MessageLookupByLibrary.simpleMessage("綠色"),
"lightLightTint8": MessageLookupByLibrary.simpleMessage("水藍色"),
"lightLightTint9": MessageLookupByLibrary.simpleMessage("藍色"),
"link": MessageLookupByLibrary.simpleMessage("連結"),
"linkAddressHint": MessageLookupByLibrary.simpleMessage("請輸入URL"),
"linkText": MessageLookupByLibrary.simpleMessage("文字"),
"linkTextHint": MessageLookupByLibrary.simpleMessage("請輸入文字"),
"ltr": MessageLookupByLibrary.simpleMessage("自左至右"),
"mobileHeading1": MessageLookupByLibrary.simpleMessage("一級標題"),
"mobileHeading2": MessageLookupByLibrary.simpleMessage("二級標題"),
"mobileHeading3": MessageLookupByLibrary.simpleMessage("三級標題"),
"numberedList": MessageLookupByLibrary.simpleMessage("有序列表"),
"opacity": MessageLookupByLibrary.simpleMessage("透明度"),
"openLink": MessageLookupByLibrary.simpleMessage("打開連結"),
"quote": MessageLookupByLibrary.simpleMessage("引文"),
"removeLink": MessageLookupByLibrary.simpleMessage("移除連結"),
"resetToDefaultColor": MessageLookupByLibrary.simpleMessage("重設為默認顏色"),
"rtl": MessageLookupByLibrary.simpleMessage("自右至左"),
"strikethrough": MessageLookupByLibrary.simpleMessage("刪除線"),
"text": MessageLookupByLibrary.simpleMessage("文本"),
"textColor": MessageLookupByLibrary.simpleMessage("文字顏色"),
"tint1": MessageLookupByLibrary.simpleMessage("色調1"),
"tint2": MessageLookupByLibrary.simpleMessage("色調2"),
"tint3": MessageLookupByLibrary.simpleMessage("色調3"),
"tint4": MessageLookupByLibrary.simpleMessage("色調4"),
"tint5": MessageLookupByLibrary.simpleMessage("色調5"),
"tint6": MessageLookupByLibrary.simpleMessage("色調6"),
"tint7": MessageLookupByLibrary.simpleMessage("色調7"),
"tint8": MessageLookupByLibrary.simpleMessage("色調8"),
"tint9": MessageLookupByLibrary.simpleMessage("色調9"),
"underline": MessageLookupByLibrary.simpleMessage("下劃線"),
"urlHint": MessageLookupByLibrary.simpleMessage("URL")
};
}

0 comments on commit e11c5b6

Please sign in to comment.