Post by Krzysiek SÅowikbut 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.