diff --git a/common/macro-recorder.js b/common/macro-recorder.js index 76c2603eb9..7fa4d865e9 100644 --- a/common/macro-recorder.js +++ b/common/macro-recorder.js @@ -64,13 +64,108 @@ this.inProgress = true; this.isFirstAction = true; + this.initEvents(); + this.editor.asc_registerCallback('asc_onKeyDown', this.onKeyDown); + this.editor.sendEvent("asc_onMacroRecordingStart"); }; + MacroRecorder.prototype.initEvents = function() + { + let _t = this; + + _t.onKeyDown = function(e) + { + if (e.KeyCode === 8) // BackSpace + { + } + else if (e.KeyCode === 9) // Tab + { + } + else if (e.KeyCode === 13) // Enter + { + } + else if (e.KeyCode === 27) // Esc + { + } + else if (e.KeyCode === 32) // Space + { + } + else if (e.KeyCode === 33) // PgUp + { + } + else if (e.KeyCode === 34) // PgDn + { + } + else if (e.KeyCode === 35) // End + { + } + else if (e.KeyCode === 36) // Home + { + } + else if (e.KeyCode === 37) // Left Arrow + { + let doc = _t.editor.getLogicDocument(); + let curPara = doc.GetCurrentParagraph(true); + let isRtl = (curPara ? curPara.isRtlDirection() : false); + + let type = isRtl + ? AscDFH.historydescription_Document_MoveCursorRight + : AscDFH.historydescription_Document_MoveCursorLeft; + + _t.addStepData(type, [{ + isRtl: isRtl, + isAddSelect: e.IsShift(), + isWord: e.IsCtrl() + }]); + } + else if (e.KeyCode === 38) // Top Arrow + { + _t.addStepData(AscDFH.historydescription_Document_MoveCursorUp, [{ + isAddSelect: e.IsShift(), + isWord: e.IsCtrl() + }]); + } + else if (e.KeyCode === 39) // Right Arrow + { + let doc = _t.editor.getLogicDocument(); + let curPara = doc.GetCurrentParagraph(true); + let isRtl = (curPara ? curPara.isRtlDirection() : false); + + let type = isRtl + ? AscDFH.historydescription_Document_MoveCursorLeft + : AscDFH.historydescription_Document_MoveCursorRight; + + _t.addStepData(type, [{ + isRtl: isRtl, + isAddSelect: e.IsShift(), + isWord: e.IsCtrl() + }]); + } + else if (e.KeyCode === 40) // Bottom Arrow + { + _t.addStepData(AscDFH.historydescription_Document_MoveCursorDown, [{ + isAddSelect: e.IsShift(), + isWord: e.IsCtrl() + }]); + } + else if (e.KeyCode === 46) // Delete + { + } + else if (e.KeyCode === 144) // Num Lock + { + } + else if (e.KeyCode === 145) // Scroll Lock + { + } + }; + }; MacroRecorder.prototype.stop = function() { if (!this.inProgress) return; - + + this.editor.asc_unregisterCallback('asc_onKeyDown', this.onKeyDown); + this.inProgress = false; this.paused = false; @@ -596,8 +691,8 @@ setStyleHeading : function(name){return "\tdoc.GetRangeBySelect().SetStyle(doc.GetStyle(\"" + name + "\"));\n"}, clearFormat : function(){return "\tdoc.GetRangeBySelect().ClearFormating()\n"}, cut : function(){return "\tdoc.GetRangeBySelect().Cut();\n"}, - changeTextCase : function(changeType){return "\tdoc.GetRangeBySelect().SetTextCase(\"" + changeType + "\");\n"}, - incFontSize : function(){return "\tdoc.GetRangeBySelect().Grow();\n"}, + changeTextCase : function(changeType){return ""; return "\tdoc.GetRangeBySelect().SetTextCase(\"" + changeType + "\");\n"}, + incFontSize : function(){return ""; return "\tdoc.GetRangeBySelect().Grow();\n"}, addLetter : function(textArr){ let textStr = ""; for (let i = 0; i < textArr.length; ++i) @@ -642,7 +737,7 @@ + "\tdoc.GetRangeBySelect().GetAllParagraphs().forEach(para => {\n\t\tpara.SetNumbering(" + CounterStore.get('numbering') + ".GetLevel(0));\n\t\tpara.SetContextualSpacing(true)\n\t});\n" }, addParagraph : function(){ - return "\tdoc.InsertParagraphAtCursor();\n"; + return "\tdoc.InsertParagraphBreak();\n"; }, addBlankPage : function(){return "\tdoc.InsertBlankPage();\n"}, addPageBreak : function(type){ @@ -1080,6 +1175,7 @@ setCellChangeTextCase : function(textCase){return "\tApi.GetSelection().ChangeTextCase(" + textCase + ");\n"}, setCellChangeFontSize : function(isInc){ // todo create api + return ""; return isInc ? "\tApi.asc_increaseFontSize();\n" : "\tApi.asc_decreaseFontSize();\n"; }, setCellBorder : function(borderArray){ @@ -1152,12 +1248,12 @@ // setCellHyperlinkRemove : function(additional) {return (additional && additional.url) ? "" : ""}, // cut : function(){return "ApiApi.GetSelection().Cut();\n"}, cellChangeValue : function(value){return "\tApi.GetSelection().SetValue(\"" + value + "\");\n"}, - setCellStyle : function(style){}, + setCellStyle : function(style){return ""}, setCellFormat : function(format){ return "\tlet " + CounterStore.inc('format') + " = Api.Format(worksheet.GetActiveCell().GetValue(), \'" + format + "\')\n" + "\tworksheet.GetActiveCell().SetValue(" + CounterStore.get('format') + ");\n"; }, - setCellHyperlinkRemove : function(data){console.log(data)}, + setCellHyperlinkRemove : function(data){return ""}, setCellMerge : function(data){ if (data === Asc.c_oAscMergeOptions.MergeCenter) return "\tApi.GetSelection().Merge(false);\n"; // + set shrink / indent @@ -1373,7 +1469,6 @@ }, clearFormatting : function(isClear){return "\tApi.GetSelection().GetShapes().forEach(shape => {\n\t\tshape.GetDocContent().GetContent().forEach(para => para.ClearFormating(" + isClear + "));\n\t})\n";}, putTextPrLineSpacing : function(lineSpacing){ - let type = lineSpacing.type; let value = lineSpacing.value; diff --git a/word/Editor/Document.js b/word/Editor/Document.js index d19562a6c5..2a89dd76b6 100644 --- a/word/Editor/Document.js +++ b/word/Editor/Document.js @@ -6456,12 +6456,6 @@ CDocument.prototype.MoveCursorLeft = function(AddToSelect, Word) isRtl = (curPara ? curPara.isRtlDirection() : false); } - this.AddMacroData(AscDFH.historydescription_Document_MoveCursorLeft, [{ - isRtl: isRtl, - isAddSelect: AddToSelect, - isWord: Word - }]); - if (isRtl) this.Controller.MoveCursorRight(AddToSelect, Word); else @@ -6490,12 +6484,6 @@ CDocument.prototype.MoveCursorRight = function(AddToSelect, Word, FromPaste) isRtl = (curPara ? curPara.isRtlDirection() : false); } - this.AddMacroData(AscDFH.historydescription_Document_MoveCursorRight, [{ - isRtl: isRtl, - isAddSelect: AddToSelect, - isWord: Word - }]); - if (isRtl) this.Controller.MoveCursorLeft(AddToSelect, Word); else @@ -20119,12 +20107,6 @@ CDocument.prototype.controller_MoveCursorUp = function(AddToSelect) this.private_UpdateCursorXY(false, true); var Result = this.private_MoveCursorUp(this.CurPos.RealX, this.CurPos.RealY, AddToSelect); - if (Result) - this.AddMacroData(AscDFH.historydescription_Document_MoveCursorUp, [{ - isWord: false, - isAddSelect: AddToSelect - }]); - // TODO: Вообще Word селектит до начала данной колонки в таком случае, а не до начала документа if (true === AddToSelect && true !== Result) this.MoveCursorToStartPos(true); @@ -20155,12 +20137,6 @@ CDocument.prototype.controller_MoveCursorDown = function(AddToSelect) this.private_UpdateCursorXY(false, true); var Result = this.private_MoveCursorDown(this.CurPos.RealX, this.CurPos.RealY, AddToSelect); - if (Result) - this.AddMacroData(AscDFH.historydescription_Document_MoveCursorDown, [{ - isWord: false, - isAddSelect: AddToSelect - }]); - if (true === AddToSelect && true !== Result) this.MoveCursorToEndPos(true); diff --git a/word/apiBuilder.js b/word/apiBuilder.js index da7c0cfc2d..db5d91a60c 100644 --- a/word/apiBuilder.js +++ b/word/apiBuilder.js @@ -9459,9 +9459,9 @@ * @returns {boolean} * @typeofeditors ["CDE"] * @since 9.2.0 - * @see office-js-api/Examples/{Editor}/ApiDocument/Methods/InsertParagraphAtCursor.js + * @see office-js-api/Examples/{Editor}/ApiDocument/Methods/InsertParagraphBreak.js */ - ApiDocument.prototype.InsertParagraphAtCursor = function() + ApiDocument.prototype.InsertParagraphBreak = function() { this.Document.AddNewParagraph(); return true;