I have a gtk.TextBuffer which is supposed to be cleared after pressing Enter, similar to the input box on most chat programs. I'm just setting the buffer back to a blank string. The newline character from Enter isn't removed though, and a blank line ends up above the cursor during the next input. Moving the cursor to the first gtk.Iter doesn't help.
By default, "gobject.connect()" callback is called before the default handler. You need to use "gobject.connect_after()".
def insert_text_cb(text_buffer, position, text, lenght):
if text == '\n':
text_buffer.set_text('')
text_view = gtk.TextView()
text_view.get_buffer().connect_after('insert-text', insert_text_cb)
Are you sure you're trigger on the proper event? Also try connecting it after.
Related
In a snake_cased language, I would want to navigate variablewise and not word_wise and also exclude sigils like #, % or / from these stops.
Example:
|$here_she_goes_again; #the pipe marks my cursor position
With one Ctrl+Right, I want to land on the space before the semicolon,
$here_she_goes_again|; #the pipe marks my cursor position
then, with a Ctrl+Left, I want to return to the beginning of the line.
|$here_she_goes_again; #the pipe marks my cursor position
Somebody got this to work?
Put this into your settings.json:
"[javascript]": {
"editor.wordSeparators": "`~!##%^&*()-=+[{]}\|;:'",.<>/?"
}
Use whatever your language identifier is. I deleted the $ from the default separators to get your example to work for javascript. You can remove the other characters you indicated. The underscore was already not in the default for me. Just make sure those characters are not in the language-specific setting shown above.
You can use the extension Select By and the command moveby.regex
You are able to define a regex to search and bind this to Ctrl+Left and another to Ctrl+Right
In the key binding you can limit this to a particular languageID.
What's an easy way to convert a multi-line comment (e.g. JSDoc with each line separated by line breaks) into a paragraph without any line breaks that I can copy into an email or another document?
I know I can use search & replace with regular expressions, but is there a more ergonomic way to do it?
You probably knew that you can use multiple cursors to change multiple lines at once, but did you know you can also use them to remove line breaks? Assume you start with this comment:
/**
* Returns a new `Temporal.LocalDateTime` instance representing the first
* valid time during the current calendar day and time zone of `this`.
*
* The local time of the result is almost always `00:00`, but in rare cases it
* could be a later time e.g. if DST starts at midnight in a time zone. For
* example:
* ```
* const ldt = Temporal.LocalDateTime.from('2015-10-18T12:00-02:00[America/Sao_Paulo]');
* ldt.startOfDay; // => 2015-10-18T01:00-02:00[America/Sao_Paulo]
* ```
*/
First part: use multiple cursors to remove the prefix characters on each line.
Click on the upper-left corner of the comment (the /**).
Now hold down Cmd+Shift (Alt+Shift on PC) and click after the */ on the last line of the comment section.
This will create a columnar, multi-line selection that includes the non-text prefix characters on each line. If the selection doesn't include all the prefix characters, you can hold down the Shift key and use the left or right arrow keys to adjust the width of the selection.
Press the Delete key to remove prefix characters on all lines.
Second part: it's time to delete the line breaks and replace them with spaces. I discovered today that you can use multiple cursors for this part too!
After you've deleted the prefix text above, but before you've pressed any other keys, press the backspace key. It will delete the line breaks but leave each cursor in the same place!
Type the spacebar once to insert one space to replace each line break.
Press ESC to clear multiple selections, and delete the extra space at the start of the line. You may have an extra space(s) at the end of the line too that may need trimming.
Copy the resulting one-line text.
Use Cmd+Z (Ctrl+Z on Windows) to undo the last few changes so your code comment will be back to normal.
Now you can paste the copied text into an email!
The same solution works to replace line breaks with spaces in any multi-line text, not only code comments.
I'm sure that many of you already knew how to do this trick, but I found it so easy and so cool that I thought it was worth sharing as a Q&A here so others can learn about this trick too.
Here's what the steps look like in the VSCode IDE:
Before deleting, you should see something like this:
After deleting prefix characters:
After deleting line breaks (note the multiple cursors are still there):
After inserting spaces in place of the deleted line breaks:
I usually select the first line break, then hit/hold command+D repeatedly to add cursors at all line endings I want to edit. Then, just hit space once.
When I move the cursor from a line without typing anything on it, VS Code seems to automatically delete the whitespace from that line so that, when I put the cursor back on that line, it ends up flush to the left, forcing me to tab to the desired indentation level again. What setting do I change to make it not do that? I tried Googling this problem but all the answers were about removing blank lines with regular expressions, which is not my issue at all.
/* Automatically remove indentation in empty lines on save */
"emptyIndent.removeIndent": true,
I’m trying to create a rectangle box on screen in PTB wherein the participant can type text that is wrapped inside this box. So I would like to get the string input to be drawn on screen while typing in a rectangular box where the text input is wrapped to avoid it continuing outside the border of this box. I have been searching for a while now and haven’t found anything that works or anyone who did this before. I assume I might be overlooking something very simple.
I have tried using:
% Textbox
Screen('FrameRect',window, white, [300 300 1600 600],4);
message = [‘Your comments: ‘];
replySubj = Ask(window, message, white, black, 'GetChar',[300 225 1600 600]);
The response input is nicely drawn on screen while typing, but only on one line that is not wrapped when I reach the side of the box, or even my screen. Is their a way to wrap the text (e.g. by integrating WrapString.m) so it stays inside a specified rectangle on screen, and continues to a new line if the text is too long for one line?
Any help is very much appreciated.
Looking at the GetEchoString function, it does the following upon each character strike (to the best of my understanding of how the display is managed):
if it is Ctrl-C, Enter, or Return: exit;
if it is Backspace, issue command to re-draw the previous full string (prompt + user input) with the same colour as the background to erase it ; then remove the last character from the stored full string;
else append the character to the stored full string.
Then issue the command to draw the resulting updated full string in the specified colour, and finally update the screen following the previous commands, with the option dontclearset to 1 (incremental drawing, cf. Screen('Flip', windowPtr, 0, 1) call).
To add wrapping capabilities, we can thus modify GetEchoString as follows:
comment out the re-drawing commands when Backspace is hit, simply updating the stored string (see below);
add a call to WrapString on the updated string to wrap it;
used DrawFormattedText to issue command to display the wrapped string;
finally, call Screen('Flip', windowPtr) that is update the screen with dontclearset to 0 (default).
The relevant part of the function are now thus:
% adapted from PTB3 GetEchoString
while true
if useKbCheck
char = GetKbChar(varargin{:});
else
char = GetChar;
end
if isempty(char)
string = '';
break;
end
switch (abs(char))
case {13, 3, 10}
% ctrl-C, enter, or return
break;
case 8
% backspace
if ~isempty(string)
% Remove last character from string:
string = string(1:length(string)-1);
end
otherwise
string = [string, char];
end
output = [msg, ' ', string];
output=WrapString(output,maxNumChar);
DrawFormattedText(windowPtr,output,x,y,textColor,[],0,0,vLineSpacing);
Screen('Flip',windowPtr);
end
Where maxNumChar and vLineSpacing are to be defined depending on your needs.
This will take care of the horizontal wrapping of the text, while keeping the Backspace function working. Note however that you could still overflow vertically if the whole screen is filled.
Most of the time after typing "new" I press Ctrl-space to quickly choose the necessary class. I want Eclipse to show the tooltip automatically, like VS+Resharper does.
If you do not have any hesitation in typing a single whitespace, you can add the whitespace character to the list of characters that will trigger the content assist dialog. The default character is the dot (.) character, to which you can add other characters.
I haven't found a way to avoid specifying any trigger character, and still get the content assist dialog. So, with the whitespace character in the list, you have to type in new instead of just new, and you can get what you desire (or more than what you need, as the dialog pops up on every space entered).