I am loading script into the Ace editor, and upon render, the entire script is highlighted as if someone did a ctrl+a (select all). How do make the contents "unselected" ... seems like it should work that way by default.
Based on documentation, it seems like I could workaround with:
session.getSelection().clearSelection();
... and based on this SO question, it seems I could also do this:
editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end
Neither work...
You may be able to remove some of the following, it's hard to say without seeing your code, but this should definitely cover it.
editor.setValue('hello world');
editor.clearSelection(1);
editor.gotoLine(1);
editor.getSession().setScrollTop(1);
editor.blur();
editor.focus();
I had the same problem, and I worked around it this way
editor.once('focus', function(){
editor.selection.clearSelection()
})
So it seems that in some cases the editor is not ready yet to accept the command.
Related
I am building a website where I want to allow people to code in almost any language that the Ace editor supports. Right now I have it redirect if they try to load a language that either isn't supported by Ace, or that I didn't list in my supported languages. I only have a few languages that I allow to run (because I haven't got others to work or don't know how to), and for all those other languages that aren't run-supported, I want to load the Ace editor with a note saying that the language they loaded isn't supported for running, but I want it to be a comment in that language.
I tried inserting the text using editor.setValue([message], -1). Then set the focus on the editor using editor.focus(). Then I select all the text with editor.selectAll(). And then use the editor.toggleCommentLines() to make it a comment. For some reason this doesn't work, and I am not sure why.
I know that I could just look up how to write comment in each of the languages that I am allowing, and then convert the message into a comment before inserting it into the editor, but I want an easier way if possible.
Is there an easier way to do it? Or should I just do what I said that I could?
Since I answered my own question, I want to ask another to see if anyone has the answer for this:
When in the Ace editor you can press CTRL+/ to toggle line comments. But if you press CTRL+SHIFT+/ it will toggle multiline comments. I don't see a function for this in the Ace editor documentation but because it works with a keyboard shortcut, there must be a way to do it programmatically, right?
If someone could figure this out, that would be great!
a user found it! See his comment to see the answer to this part.
I was trying a few more things, and one of them was doing a setTimeout on the editor.toggleCommentLines(), and that worked. The timeout worked best if I used 150ms or higher (I started with 2000 just to see if it worked at all, and then slowly moved down).
So the following code works to automatically insert a message and comment it out:
const editor = ace.edit([element]);
editor.setValue([message], 0); // You can also leave the second parameter blank, 0 is the default which automatically selects all.
setTimeout(() => {
editor.toggleCommentLines();
}, 150); // 150ms or more works best
You may also notice that this method clears out 2 methods that I was previously using. There are two reasons for this:
When using 0 instead of -1 for the second parameter of editor.setValue() it selects all the text.
Because we are using the editor variable, the editor doesn't need to be in "focus".
I have in my one qfl file about 14 functions that I call to my action. But generally when I open the solution file ever morning and navigate to the function file, all the functions are expanded again.
Then I need to click on every single function to collapse it - I do this because it helps navigate through the file quicker because there is now only one line of code for each function to scroll through instead of scrolling through every line inside the function ONLY to go past it.
Yes, I am aware that this doesn't even take a minute to do, but I am trying to be efficient and as a programmer in general, I'm just lazy and don't want to repeat this everyday.
I cannot seem to find a solution anywhere for this.
Is it possible to create a button or shortcut key that can do this?
If I have posted this in the wrong place, please advise where to post it. :)
While using the amazing Python Jedi plugin from GVim, I have started noticing some odd behavior with function completion tips popup (not the autocomplete as far as I can tell).
Firstly, while the function argument helper popup is visible, GVim input becomes laggy, even for builtin functions and standard types. Once the popup is closed, lag disappears. Autocomplete seems to work just fine on all levels, this lag seems to only apply to the function helper.
Secondly, I recently had a case where a popup became frozen in the buffer, even after it should have closed, and actually replaced the contents of the buffer at that location in the file. I finished the function I was working on, and then used :/__init to jump cursor location. My window scrolled down, but apparently the original function popup didn't clear, and become a fixture in my text.
When I saved the file, that line was replaced with the popup contents (obviously threw an Exception when python tried to execute that line). Going back to that location in the file, reactivating that function help popup and then closing it again fixed the frozen popup text.
Are these problems related?
Is this an aggressive configuration setting that I should change. Honestly those popups are a bit too aggressive for my liking sometimes, so how do I disable/hotkey-bind them in the configuration?
I have only experienced this behavior in GVim. Maybe it happens in console vim, but I have not tried to reproduce the situation, so I don't know.
GVim circumstances:
7 tabs open
each tab usually has two vertical windows
each window is usually a separate python module
There's a multitude of issues about this on jedi-vim's issue tracker: https://github.com/davidhalter/jedi-vim/issues/217. The whole lag situation is slowly getting better.
One of the easiest solutions is to just disable call signatures:
g:jedi#show_call_signatures = "0"
As of now (I just merged that), there's another way of displaying call signatures:
The call signatures can be displayed as a pop-up in the buffer (set to
1, the default), which has the advantage of being easier to refer to,
or in Vim's command line aligned with the function call (set to 2),
which can improve the integrity of Vim's undo history.
You could try if you like this better (but you have to update jedi-vim):
g:jedi#show_call_signatures = "2"
I've added some code as found here Big problems with MFC/WinAPI to colour tab titles the same as the reset of the dialog, which works, but unfortunately all the tabs end up with the same name. This doesn't surprise me all that much as GetCurSel() is used to grab the text to use, and only one tab can currently be selected, but I'm struggling to see how you access the correct tab index from OnDrawItem().
I've googled and had a look on MSDN but don't see how anything passed to OnDrawItem lets you know which tab is currently being drawn, rather all the examples I've seen assume you're only interested in the one currently selected. All I want to do is something along the lines of GetWindowText() on the child window and redraw with that. I'm also unsure of the parent/child/sibling relationship between the sheet, tab control and page - it depends who you listen to.
I should probably add that I'm also unsure why all the tabs are redrawn when I select one. I don't know if this is normal or something specific to this implementation (that's something I'm looking at, but like seemingly everything else in this code base it's multiply inherited several times over ...).
Cheers for any help.
Not to worry, I now realise lpDrawItemStruct->itemID holds the tab index so I can get a handle to the tab using that.
I have a GUI menu on Matlab with 4 buttons (menu.fig). Then I have 4 .fig file that I want to open when I click on the buttons. Here it's all ok, when I open a .fig from menu and insert value to do a plot I get this error:
???? Attempt to reference field of non-structure array.
If I try to open 1.fig directly, everything works perfectly.
I read that the problem is with eval(), but I can't solve it.
I changed the variable names on each .fig file
One 1.fig:
function pbutton1_Callback(hObject, eventdata, handles)
A1=get(handles.edtSAmp,'String');
f1=get(handles.edtSFreq, 'String');
fi1=get(handles.edtSFase, 'String');
t1=get(handles.popTipo, 'Value');
A1=str2double(A1);
f1=str2double(f1);
fi=str2double(fi1);
SinalSinusoidal(A1,f1,fi,t1);
I got the error on the that 1st line.
I guess this is something MATLAB GUI not handled well. I know it used to work, but when you tweaking your UI or UI related code a bit and accidentally you modified some area MATLAB told you not to touch, this kind of issue begin to happen.
The workaournd is to start the GUI from M editor by clicking run
I know it works, but originally, when I directly lauch it , it works too. so, this is not the end of it, people are just not getting to the end of it.
The problem is with probably with handles1. It's not a structure array like you expect it to be. In GUI's created with GUIDE, this variable is usually called handles, if you have both handles and handles1 make sure handles1 contains handles to the objects in the figure. If you're using handles1 only, make sure you're initializing it properly.