Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility adaptation to versions R2021b and on #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion +Snippet/+Variable/directory.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion +Snippet/+Variable/fileName.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion +Snippet/+Variable/fileNameBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion +Snippet/+Variable/filePath.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions +Snippet/+Variable/lineIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion +Snippet/+Variable/lineNumber.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified MATLAB Snippets.mlappinstall
Binary file not shown.
22 changes: 7 additions & 15 deletions MATLAB Snippets.prj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<deployment-project plugin="plugin.apptool" plugin-version="1.0">
<configuration build-checksum="1438619341" file="C:\work\repo\github\snippets\MATLAB Snippets.prj" location="C:\work\repo\github\snippets" name="MATLAB Snippets" target="target.mlapps" target-name="Package App">
<configuration build-checksum="3174802341" file="C:\Users\Jonathan Zea\Documents\matlab-snippets\MATLAB Snippets.prj" location="C:\Users\Jonathan Zea\Documents\matlab-snippets" name="MATLAB Snippets" target="target.mlapps" target-name="Package App">
<param.appname>MATLAB Snippets</param.appname>
<param.authnamewatermark>Pavel Trnka</param.authnamewatermark>
<param.email>pavel@trnka.name</param.email>
<param.authnamewatermark>Jonathan Zea</param.authnamewatermark>
<param.email>jonathan.a.zea@ieee.org</param.email>
<param.company />
<param.icon>${PROJECT_ROOT}\MATLAB Snippets_resources\icon_24.png</param.icon>
<param.icons>
Expand All @@ -20,7 +20,7 @@
&lt;/ul&gt;
Snippets definition uses syntax compatible with &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets"&gt;Visual Studio Code&lt;/a&gt; and &lt;a href="https://macromates.com/manual/en/snippets"&gt;Textmate&lt;/a&gt;.</param.description>
<param.screenshot>${PROJECT_ROOT}\graphics\screenshot01.png</param.screenshot>
<param.version>1.0</param.version>
<param.version>2.3</param.version>
<param.products.name />
<param.products.id />
<param.products.version />
Expand All @@ -29,7 +29,6 @@ Snippets definition uses syntax compatible with &lt;a href="https://code.visuals
<param.guid>8bfd37e6-10e5-4889-84a4-6c68df10c1c1</param.guid>
<unset>
<param.company />
<param.version />
<param.products.name />
<param.products.id />
<param.products.version />
Expand Down Expand Up @@ -90,19 +89,12 @@ Snippets definition uses syntax compatible with &lt;a href="https://code.visuals
</fileset.resources>
<fileset.package />
<build-deliverables>
<file location="C:\work\repo\github" name="snippets" optional="false">C:\work\repo\github\snippets</file>
<file location="C:\Users\Jonathan Zea\Documents" name="matlab-snippets" optional="false">C:\Users\Jonathan Zea\Documents\matlab-snippets</file>
</build-deliverables>
<workflow />
<matlab>
<root>C:\Program Files\MATLAB\R2019b</root>
<toolboxes>
<toolbox name="neuralnetwork" />
</toolboxes>
<toolbox>
<neuralnetwork>
<enabled>true</enabled>
</neuralnetwork>
</toolbox>
<root>C:\Program Files\MATLAB\R2023a</root>
<toolboxes />
</matlab>
<platform>
<unix>false</unix>
Expand Down
19 changes: 16 additions & 3 deletions insertSnippet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion utils/editor/getLineAtCaretPosition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion utils/editor/getWordAtCaretPosition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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*$');
Expand Down