diff --git a/+Snippet/+Variable/directory.m b/+Snippet/+Variable/directory.m index 89de243..dd9189e 100644 --- a/+Snippet/+Variable/directory.m +++ b/+Snippet/+Variable/directory.m @@ -4,6 +4,10 @@ if isempty(activeEditor) out = ''; else - out = fileparts( char( activeEditor.JavaEditor.getLongName ) ); + if verLessThan('matlab', '9.11.0') + out = fileparts( char( activeEditor.JavaEditor.getLongName ) ); + else + out = fileparts( activeEditor.Filename ); + end end end diff --git a/+Snippet/+Variable/fileName.m b/+Snippet/+Variable/fileName.m index 4dc0ea1..7694161 100644 --- a/+Snippet/+Variable/fileName.m +++ b/+Snippet/+Variable/fileName.m @@ -4,6 +4,11 @@ if isempty(activeEditor) out = ''; else - out = char( activeEditor.JavaEditor.getShortName ); + if verLessThan('matlab', '9.11.0') + out = char( activeEditor.JavaEditor.getShortName ); + else + [~, file, ext] = fileparts( activeEditor.Filename ); + out = [ file, ext ]; + end end end diff --git a/+Snippet/+Variable/fileNameBase.m b/+Snippet/+Variable/fileNameBase.m index 5b29e1c..a0c2993 100644 --- a/+Snippet/+Variable/fileNameBase.m +++ b/+Snippet/+Variable/fileNameBase.m @@ -4,6 +4,10 @@ if isempty(activeEditor) out = ''; else - [~,out] = fileparts( char( activeEditor.JavaEditor.getLongName ) ); + if verLessThan('matlab', '9.11.0') + [~,out] = fileparts( char( activeEditor.JavaEditor.getLongName ) ); + else + [~, out] = fileparts( activeEditor.Filename ); + end end end \ No newline at end of file diff --git a/+Snippet/+Variable/filePath.m b/+Snippet/+Variable/filePath.m index 0110519..14be3ac 100644 --- a/+Snippet/+Variable/filePath.m +++ b/+Snippet/+Variable/filePath.m @@ -4,6 +4,10 @@ if isempty(activeEditor) out = ''; else - out = char( activeEditor.JavaEditor.getLongName ); + if verLessThan('matlab', '9.11.0') + out = char( activeEditor.JavaEditor.getLongName ); + else + out = activeEditor.Filename; + end end end diff --git a/+Snippet/+Variable/lineIndex.m b/+Snippet/+Variable/lineIndex.m index aa68358..90d8e65 100644 --- a/+Snippet/+Variable/lineIndex.m +++ b/+Snippet/+Variable/lineIndex.m @@ -3,7 +3,11 @@ activeEditor = getActiveEditor(); if isempty(activeEditor) out = ''; -else - out = num2str( activeEditor.JavaEditor.getLineNumber ); +else + if verLessThan('matlab', '9.11.0') + out = num2str( activeEditor.JavaEditor.getLineNumber ); + else + out = activeEditor.Selection(1) - 1; + end end end \ No newline at end of file diff --git a/+Snippet/+Variable/lineNumber.m b/+Snippet/+Variable/lineNumber.m index 67c0876..7513071 100644 --- a/+Snippet/+Variable/lineNumber.m +++ b/+Snippet/+Variable/lineNumber.m @@ -4,6 +4,10 @@ if isempty(activeEditor) out = ''; else - out = num2str( activeEditor.JavaEditor.getLineNumber+1 ); + if verLessThan('matlab', '9.11.0') + out = num2str( activeEditor.JavaEditor.getLineNumber+1 ); + else + out = activeEditor.Selection(1); + end end end \ No newline at end of file diff --git a/MATLAB Snippets.mlappinstall b/MATLAB Snippets.mlappinstall index 602f268..75c38a3 100644 Binary files a/MATLAB Snippets.mlappinstall and b/MATLAB Snippets.mlappinstall differ diff --git a/MATLAB Snippets.prj b/MATLAB Snippets.prj index a4b7bab..97b5300 100644 --- a/MATLAB Snippets.prj +++ b/MATLAB Snippets.prj @@ -1,8 +1,8 @@ - + MATLAB Snippets - Pavel Trnka - pavel@trnka.name + Jonathan Zea + jonathan.a.zea@ieee.org ${PROJECT_ROOT}\MATLAB Snippets_resources\icon_24.png @@ -20,7 +20,7 @@ </ul> Snippets definition uses syntax compatible with <a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets">Visual Studio Code</a> and <a href="https://macromates.com/manual/en/snippets">Textmate</a>. ${PROJECT_ROOT}\graphics\screenshot01.png - 1.0 + 2.3 @@ -29,7 +29,6 @@ Snippets definition uses syntax compatible with <a href="https://code.visuals 8bfd37e6-10e5-4889-84a4-6c68df10c1c1 - @@ -90,19 +89,12 @@ Snippets definition uses syntax compatible with <a href="https://code.visuals - C:\work\repo\github\snippets + C:\Users\Jonathan Zea\Documents\matlab-snippets - C:\Program Files\MATLAB\R2019b - - - - - - true - - + C:\Program Files\MATLAB\R2023a + false diff --git a/insertSnippet.m b/insertSnippet.m index 914c1bd..12048af 100644 --- a/insertSnippet.m +++ b/insertSnippet.m @@ -931,7 +931,11 @@ function insertToEditor(text,alwaysDeleteWordAtCaret) if ~isempty(activeEditor) % --- Get tabstop $0 position - caretPosition = activeEditor.JavaEditor.getCaretPosition; + if verLessThan('matlab', '9.11.0') + caretPosition = activeEditor.JavaEditor.getCaretPosition; + else + caretPosition = matlab.desktop.editor.positionInLineToIndex(activeEditor, activeEditor.Selection(1), activeEditor.Selection(2)) - 1; + end indCaret = parsedSnippet.getPlaceholderPosition(0); if ~isempty(indCaret) indCaret = indCaret(1); @@ -940,11 +944,20 @@ function insertToEditor(text,alwaysDeleteWordAtCaret) end % --- Insert text to the editor - activeEditor.JavaEditor.insertTextAtCaret(text); + if verLessThan('matlab', '9.11.0') + activeEditor.JavaEditor.insertTextAtCaret(text); + else + activeEditor.insertTextAtPositionInLine(text, activeEditor.Selection(1), activeEditor.Selection(2)); + end % --- Move the caret to the $0 tabstop if ~isempty(indCaret) - activeEditor.JavaEditor.setCaretPosition( caretPosition + indCaret - 1 ); + if verLessThan('matlab', '9.11.0') + activeEditor.JavaEditor.setCaretPosition( caretPosition + indCaret - 1 ); + else + [temp_line, temp_position] = matlab.desktop.editor.indexToPositionInLine(activeEditor, caretPosition + 1 + indCaret - 1); + activeEditor.goToPositionInLine(temp_line, temp_position); + end end end diff --git a/utils/editor/getLineAtCaretPosition.m b/utils/editor/getLineAtCaretPosition.m index cc3afca..ff4d970 100644 --- a/utils/editor/getLineAtCaretPosition.m +++ b/utils/editor/getLineAtCaretPosition.m @@ -7,7 +7,11 @@ activeEditor = getActiveEditor(); if ~isempty(activeEditor) - caretPosition = activeEditor.JavaEditor.getCaretPosition; + if verLessThan('matlab', '9.11.0') + caretPosition = activeEditor.JavaEditor.getCaretPosition; + else + caretPosition = matlab.desktop.editor.positionInLineToIndex(activeEditor, activeEditor.Selection(1), activeEditor.Selection(2)) - 1; + end text = activeEditor.Text; if isempty(text) diff --git a/utils/editor/getWordAtCaretPosition.m b/utils/editor/getWordAtCaretPosition.m index 1f567c2..7c11c2b 100644 --- a/utils/editor/getWordAtCaretPosition.m +++ b/utils/editor/getWordAtCaretPosition.m @@ -7,7 +7,13 @@ activeEditor = getActiveEditor(); if ~isempty(activeEditor) - caretPosition = activeEditor.JavaEditor.getCaretPosition; + + if verLessThan('matlab', '9.11.0') + caretPosition = activeEditor.JavaEditor.getCaretPosition; + else + caretPosition = matlab.desktop.editor.positionInLineToIndex(activeEditor, activeEditor.Selection(1), activeEditor.Selection(2)) - 1; + end + text = activeEditor.Text; [startIndex,endIndex] = regexp(text(1:caretPosition),'\S*$');