Discussion:
2 requested features with selection
Krzysiek Słowik
2013-12-05 09:12:45 UTC
Permalink
I would like to have 2 features:
- select the next occurrence of the current word.
(like in sublimetext: ctrl+D and I have selected next occurence of my selected text)
- select all occurences of the current word or selection
(like in sublimetext: ALT+F3 and I have selected all occurences)

It is very useful to work with multiselections.
This features works in sublimetext. Its awesome.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Jamie Macdougall
2013-12-05 15:53:30 UTC
Permalink
Agreed these are very useful.
However charLeft,charLeftExtend, wordLeft, enter etc only apply to the main
selection, so these would all need to be updated as well.
Post by Krzysiek Słowik
- select the next occurrence of the current word.
(like in sublimetext: ctrl+D and I have selected next occurence of my selected text)
- select all occurences of the current word or selection
(like in sublimetext: ALT+F3 and I have selected all occurences)
It is very useful to work with multiselections.
This features works in sublimetext. Its awesome.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Eric Promislow
2013-12-05 17:43:31 UTC
Permalink
We implemented the Ctrl-D part of this in Komodo: Repeated invocations of
"cmd_addNextWordToCaretSet" (which by default is bound to Ctrl-D,
conveniently never used some 13 into Komodo's life) does this.

However, there are plenty of corner cases, so we end the multi-caret
session on almost any non-typing character. Backspaces are handled, but if
you backspace to the left of the starting spot, the session ends.

While playing with the feature in the aforementioned editor I found plenty
of weird cases at the boundaries. I'd support making it easier to implement
this at the application level, and not making it a core feature in
Scintilla.

- Eric
Post by Jamie Macdougall
Agreed these are very useful.
However charLeft,charLeftExtend, wordLeft, enter etc only apply to the
main selection, so these would all need to be updated as well.
Post by Krzysiek Słowik
- select the next occurrence of the current word.
(like in sublimetext: ctrl+D and I have selected next occurence of my selected text)
- select all occurences of the current word or selection
(like in sublimetext: ALT+F3 and I have selected all occurences)
It is very useful to work with multiselections.
This features works in sublimetext. Its awesome.
--
You received this message because you are subscribed to the Google Groups
"scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Teodor Petrov
2013-12-05 22:26:05 UTC
Permalink
Post by Eric Promislow
We implemented the Ctrl-D part of this in Komodo: Repeated invocations
of "cmd_addNextWordToCaretSet" (which by default is bound to Ctrl-D,
conveniently never used some 13 into Komodo's life) does this.
However, there are plenty of corner cases, so we end the multi-caret
session on almost any non-typing character. Backspaces are handled,
but if you backspace to the left of the starting spot, the session ends.
While playing with the feature in the aforementioned editor I found
plenty of weird cases at the boundaries. I'd support making it easier
to implement this at the application level, and not making it a core
feature in Scintilla.
Hi,

I've also implemented this in Code::Blocks and I find it very useful.
What I need as an API
or feature in Scintilla is an undo for the selection. At the moment the
user should be very
careful using these commands, because there is no undo, so if he/she
makes a mistake,
then he/she should start all over. And this is quite annoying.

Best regards,
Teodor
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Eric Promislow
2013-12-05 22:33:21 UTC
Permalink
I push an undo-block when I detect an editing operation, before handing the
key event to Scintilla,and pop the undo-block when the editing session
ends. Which means an undo takes you to the state you were in at the start
of setting all the selection points. The only alternative is to make each
key-event an undoable block, but I found that looked clunky.

- Eric
Post by Eric Promislow
We implemented the Ctrl-D part of this in Komodo: Repeated invocations of
"cmd_addNextWordToCaretSet" (which by default is bound to Ctrl-D,
conveniently never used some 13 into Komodo's life) does this.
However, there are plenty of corner cases, so we end the multi-caret
session on almost any non-typing character. Backspaces are handled, but if
you backspace to the left of the starting spot, the session ends.
While playing with the feature in the aforementioned editor I found
plenty of weird cases at the boundaries. I'd support making it easier to
implement this at the application level, and not making it a core feature
in Scintilla.
Hi,
I've also implemented this in Code::Blocks and I find it very useful. What
I need as an API
or feature in Scintilla is an undo for the selection. At the moment the
user should be very
careful using these commands, because there is no undo, so if he/she makes
a mistake,
then he/she should start all over. And this is quite annoying.
Best regards,
Teodor
--
You received this message because you are subscribed to the Google Groups
"scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Neil Hodgson
2013-12-05 23:40:19 UTC
Permalink
We implemented the Ctrl-D part of this in Komodo: Repeated invocations of "cmd_addNextWordToCaretSet" (which by default is bound to Ctrl-D, conveniently never used some 13 into Komodo's life) does this.
However, there are plenty of corner cases, so we end the multi-caret session on almost any non-typing character. Backspaces are handled, but if you backspace to the left of the starting spot, the session ends.
Here’s a simple implementation for SciTE as a Lua macro. It only uses selections, unlike Komodo which also uses indicators, so the selection set is more fragile than Komodo, which has both advantages and disadvantages.

function MultiSelectCurrent()
local initialSelection = props["CurrentSelection"]
local searchText = initialSelection
local start = editor.SelectionEnd
if searchText == "" then
-- Select current word
start = editor:WordStartPosition(start)
searchText = editor:textrange(start, editor:WordEndPosition(start))
end
-- Could tweak searching to only find words or be case-insensitive
local searchFlags = SCFIND_MATCHCASE
local matchPosition = editor:findtext(searchText, searchFlags, start, editor.Length)
if matchPosition == nil then
-- Wrap around to start of document
matchPosition = editor:findtext(searchText, searchFlags, 0, editor.SelectionStart)
end
if matchPosition ~= nil then
if initialSelection == "" then
editor:SetSelection(matchPosition + #searchText, matchPosition)
else
editor:AddSelection(matchPosition + #searchText, matchPosition)
end
editor:ScrollCaret()
end
end

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Krzysiek Słowik
2013-12-06 09:35:36 UTC
Permalink
I have written similar function for myself

function ExtendSelectionToWord()
-- swap vars
if editor.Anchor > editor.CurrentPos then
local tmp = editor.Anchor
editor.Anchor = editor.CurrentPos
editor.CurrentPos = tmp
end
local selectedWord = editor:textrange(editor.Anchor, editor.CurrentPos)
local b,e = editor:findtext(selectedWord, SCFIND_MATCHCASE,
editor.CurrentPos);
if e and b then
editor:AddSelection(e, b)
editor:ScrollCaret()
end
end

but i would like to use this feature in Notepad++ (not only in SciTe).

Most modern editors jak sublimetext or everEdit has this features.

In my opinion scintilla should have more features with multiselection.
@Neil: Did you think (or plan) to add this features to scintilla?
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Neil Hodgson
2013-12-07 02:48:10 UTC
Permalink
Post by Krzysiek Słowik
but i would like to use this feature in Notepad++ (not only in SciTe).
Most modern editors jak sublimetext or everEdit has this features.
In my opinion scintilla should have more features with multiselection.
@Neil: Did you think (or plan) to add this features to scintilla?
There may be differences in how different users and applications want this to work. The first area of difference would be in which search flags are used: some may want case-sensitive or case-insensitive or only whole word matching. Another potential choice is in the scope of the search with your code only searching from the current position to the document end, and mine wrapping to the document start. Other applications may want to limit the search to the current class or current sub-language or similar. Then there is the question of what to do when the selection is empty with many wanting the current ‘word’ to be selected. Applications may have custom definitions for ‘word’ with, perhaps, ‘$’ and ‘-‘ being included in words for some sections of the document but not others.

When Scintilla chooses a particular set of options for an operation there are (inevitably) users that want to change the options and this can lead to a complex set of parameters and modes. Even after defining the above mentioned 3 options, that wouldn’t be useful to applications like Komodo which want to implement different concepts of selection durability. Generally its better to provide the components of such operations and allow applications to combine them as they want.

Here is a more complete suite of 4 operations defined for SciTE in Lua. Ctrl+2: Select all instances of selection or word around caret; Ctrl+3: Select next occurrence of selection or word around empty selection; Ctrl+4: Deselect main selection; Ctrl+5: Make next selection the main selection (rotate).

Having a deselect main selection operation allows fixing the common problem of selecting too many occurrences in a similar way to allowing selection operations to be undone. In conjunction with a command to rotate between selections, it allows the user to better refine the selection set.

Out of this code, I’d be inclined to add DropLastMultiSelect as a Scintilla API although its possible that an application may want to change which selection becomes the new main selection. Another element that could be changed to make client code simpler is to add a wraparound flag to finding text. There may be issues with matches that straddle the start point.

function Select(caret, anchor, set)
if set then
editor:SetSelection(caret, anchor)
else
editor:AddSelection(caret, anchor)
end
end

function MultiSelectAllCurrent()
local search = props["CurrentSelection"]
if search == "" then
-- Select current word
local start = editor:WordStartPosition(editor.SelectionEnd)
search = editor:textrange(start, editor:WordEndPosition(start))
end
local searchFlags = SCFIND_MATCHCASE
local first = true
for match in editor:match(search, searchFlags) do
Select(match.pos + match.len, match.pos, first)
first = false
end
editor:ScrollCaret()
end

function MultiSelectCurrent()
local initialSelection = props["CurrentSelection"]
local search = initialSelection
local start = editor.SelectionEnd
if search == "" then
-- Select current word
start = editor:WordStartPosition(start)
search = editor:textrange(start, editor:WordEndPosition(start))
end
-- Could tweak searching to only find words or be case-insensitive
local searchFlags = SCFIND_MATCHCASE
local matchPosition = editor:findtext(search, searchFlags, start, editor.Length)
if matchPosition == nil then
-- Wrap around to start of document
matchPosition = editor:findtext(search, searchFlags, 0, editor.SelectionStart)
end
if matchPosition then
Select(matchPosition + #search, matchPosition, initialSelection == "")
editor:ScrollCaret()
end
end

function DropLastMultiSelect()
if editor.Selections > 1 then
local selections = {}
for sel = 0, editor.Selections-1 do
if sel ~= editor.MainSelection then
table.insert(selections, { editor.SelectionNCaret[sel], editor.SelectionNAnchor[sel] })
end
end
for i, sel in ipairs(selections) do
Select(sel[1], sel[2], i == 1)
end
editor:ScrollCaret()
end
end

function RotateMultiSelect()
editor:RotateSelection()
editor:ScrollCaret()
end

# In user properties
command.2.*=MultiSelectAllCurrent()
command.name.2.*=MultiSelectAllCurrent
command.subsystem.2.*=3
command.save.before.2.*=2
command.3.*=MultiSelectCurrent()
command.name.3.*=MultiSelectCurrent
command.subsystem.3.*=3
command.save.before.3.*=2
command.4.*=DropLastMultiSelect()
command.name.4.*=DropLastMultiSelect
command.subsystem.4.*=3
command.save.before.4.*=2
command.5.*=RotateMultiSelect()
command.name.5.*=RotateMultiSelect
command.subsystem.5.*=3
command.save.before.5.*=2
# Make the additional selections more distinct
selection.additional.back=#008080
selection.additional.alpha=63

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Neil Hodgson
2013-12-15 22:42:44 UTC
Permalink
Out of this code, I’d be inclined to add DropLastMultiSelect as a Scintilla API although its possible that an application may want to change which selection becomes the new main selection.
This is now implemented but not yet committed.

The API is DropSelectionN(int selection) which allows the application to drop any piece of a multiple-selection. When the selection being dropped is the main selection then the previous selection is made main. The common use will be to drop the main selection like this use in Lua for SciTE:

function DropLastMultiSelect()
editor:DropSelectionN(editor.MainSelection)
editor:ScrollCaret()
end

The term ‘drop’ is used because I thought ‘delete’ or ‘remove’ implied deletion of the text in that selection.

A patch implementing the new API is attached.

Neil
Neil Hodgson
2013-12-18 22:31:55 UTC
Permalink
The API is DropSelectionN(int selection) …
This has now been committed.

Another potential feature mentioned was to add a wrapping flag to search APIs. I tried to find a use for this in SciTE but it didn’t make any code simpler, so won’t be implementing it.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scintilla-interest+***@googlegroups.com.
To post to this group, send email to scintilla-***@googlegroups.com.
Visit this group at http://groups.google.com/group/scintilla-interest.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...