- Offizieller Beitrag
Ich stehe hier vor einem sehr seltsamen Verhalten beim Setzen von Selektionen.
Das folgende Skript bewirkt, dass das unter dem Cursor stehende Wort selektiert wird. Dies kann entweder für die Wordcharacter gelten (mit Strg+Shift+E) oder zusätzlich mit führendem "$" für Variablen (mit Strg+E).
Das funktioniert auch tadellos - solange rechts neben dem Begriff ein Leerzeichen steht. Ist dies jedoch nicht so, Dann werden Bereiche selektiert, die nicht mit den Markern übereinstimmen.
Es spielt übrigens keine Rolle, wie ich die Selektion ausführe ( SelectionStart/-Stop; SetSel(); CharRightExtend() ), immer dasselbe Verhalten.
Vielleicht hat jemand eine Idee..
[Ich habe das Problem auch im EN-Forum gepostet.]
Edit: Problem gelöst! Ursache war, dass SciTe als Standard den HotKey "Strg+E" nutzt um die nächste Klammer zu finden.
Spoiler anzeigen
-------------------------------------------------------------------------
EditKey = EventClass:new(Common)
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-- expand selection to full variable ($variable) or only the word characters (variable)
---------------- SetSelection( ) -----------------------------------------
function SetSelection(_part)
local isWordChar = function(_char)
if string.char(_char):find('[a-zA-Z0-9_]') then return true end
return false
end
local iStart = editor.CurrentPos
local iEnd = iStart
while isWordChar(editor.CharAt[iStart-1]) do
iStart = iStart - 1
end
if string.char(editor.CharAt[iStart-1]) == "$" and _part == false then iStart = iStart - 1 end
while isWordChar(editor.CharAt[iEnd]) do
iEnd = iEnd + 1
end
if iStart ~= iEnd then
editor.SelectionStart = iStart
editor.SelectionEnd = iEnd
end
end -->SetSelection
-------------------------------------------------------------------------
----------------- Event: OnKey -----------------------------------------
function EditKey:OnKey(_keycode, _shift, _ctrl, _alt)
if _ctrl and _shift and not _alt and _keycode == 69 then SetSelection(true) end --- expand selection to full word with only Wordcharacters
if _ctrl and not _shift and not _alt and _keycode == 69 then SetSelection(false) end --- expand selection to full word with Wordcharacters and leading "$"
return nil
end --> EditKey
-------------------------------------------------------------------------
Alles anzeigen