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

Conversation

ztjona
Copy link

@ztjona ztjona commented Feb 11, 2022

Fixes #3

Solution:
I followed the suggestion of gwoo in the Matlab FileExchange discussion.
https://www.mathworks.com/matlabcentral/fileexchange/70524-matlab-snippets?s_tid=mlc_fex_email_activity#discussions_2427370

@ztjona ztjona mentioned this pull request Mar 13, 2022
@jruiz72
Copy link

jruiz72 commented Jun 6, 2023

Hi Ztjona, I was using this pull request, thanks it works nice. I was trying to do the "Example - Inserting a snippet without tabstops" shown in the documentation (https://la.mathworks.com/matlabcentral/fileexchange/70524-matlab-snippets) but there's a problem, I think it is with the file "clearWordAtCaretPosion".

image

Maybe a similar adjustment to those you did in the other files needs to be done in this file. Thanks in advance

@ztjona
Copy link
Author

ztjona commented Jun 7, 2023

Oh, yeah, you are right. The function clearWordAtCaretPosion needs to have a similar fix to replace the code that mentions the JavaEditor.

function clearWordAtCaretPosion()
[wordAtCaret,i1,i2] = getWordAtCaretPosition();
if ~isempty(wordAtCaret)   
    activeEditor = getActiveEditor();
    % --- Select the word
    activeEditor.JavaEditor.setSelection(i1-1,i2);
    % --- Insert empty text to delete the selected word
    activeEditor.JavaEditor.insertTextAtCaret('');
end
end

In this case, though, I could not come up with a reasonable solution. I tried with the function:

activeEditor.insertTextAtPositionInLine(TEXT, LINE, POSITION)

but it can not delete the previous text.

A workaround could involve the property activeEditor.Text. But it replaces all the text in the file.

activeEditor.Text = NEW_TEXT;

And sadly, the property activeEditor.SelectedText is read-only.
github matlab insert snipet

I did not find any other method or property to solve it, and as I haven't bumped into an scenario where it is urgent to fix it, I have left it for another moment.

@ghost
Copy link

ghost commented Jun 7, 2023

is there a way to make it work? maybe it's easier without it deleting the prefix??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants