SciLexer tab key - line indent vs. tab insert
Posted: 13 Nov 2022 15:23
How can I change the editor's response to a tab key press from line indent to tab insert ?
Visual Prolog Discussion forums
https://discuss.visual-prolog.com/
Code: Select all
tabWidth := 4,
tabIndents := true,
backSpaceUnIndents := true,
useTabs := false,
Code: Select all
mySciLexer_ctl:addShowListener(
{ :-
mySciLexer_ctltabWidth := 8,
mySciLexer_ctl:tabIndents := false,
mySciLexer_ctl:backSpaceUnIndents := false,
mySciLexer_ctl:useTabs := true
}),
Code: Select all
new(Parent) :-
dialog::new(Parent),
generatedInitialize(),
sciLexer_ctl:addShowListener(
{ :-
sciLexer_ctl:tabWidth := 8,
sciLexer_ctl:tabIndents := false,
sciLexer_ctl:backSpaceUnIndents := false,
sciLexer_ctl:useTabs := true,
sciLexer_ctl:text := "Hello" % confirms that the listener is being called
}).
And further this predicate makes:Thomas Linder Puls wrote: ↑14 Nov 2022 9:30 Our show predicate for the sciLexer makes the following settings:
Code: Select all
clearCmdKey(key_tab), % handled in onNative to get old Visual Prolog behaviour
clearCmdKey(shift+key_tab), % handled in onNative to get old Visual Prolog behaviour
Code: Select all
new(Parent) :-
dialog::new(Parent),
generatedInitialize(),
sciLexer_ctl:addShowListener(
{ :-
sciLexer_ctl:tabWidth := 8,
sciLexer_ctl:tabIndents := false,
sciLexer_ctl:backSpaceUnIndents := false,
sciLexer_ctl:useTabs := true,
sciLexer_ctl:text := "Hello", % confirms that the listener is being called
sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexerBase::key_tab) % <== does not change tab behavior
}).
Code: Select all
sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexerBase::key_tab)
Code: Select all
sciLexer_ctl:assignCmdKey(sciLexerBase::key_tab, sciLexer_native::sci_tab),
Code: Select all
% sciLexer.pro, line 225
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
tryGetKeydownAction(c_Control, vk_Ckey) = copy.
tryGetKeydownAction(c_Control, vk_insert) = copy.
tryGetKeydownAction(c_Control, vk_Xkey) = cut.
tryGetKeydownAction(c_Shift, vk_delete) = cut.
tryGetKeydownAction(c_Nothing, vk_tab) = tab_vip.
tryGetKeydownAction(c_Shift, vk_tab) = backTab_vip.
clauses
tab_vip() :-
changeIndent(true).
clauses
backtab_vip() :-
changeIndent(false).
predicates
changeIndent : (boolean Forward).
clauses
changeIndent(Forward) :-
beginUndoAction(),
try
IndentStep = indentStep,
IndentIncrease = if true = Forward then IndentStep else -IndentStep end if,
LineStart = lineFromPosition(selectionStart),
LineEnd1 = lineFromPosition(selectionEnd),
LineEnd = if LineStart < LineEnd1 and selectionEnd = positionFromLine(LineEnd1) then LineEnd1 - 1 else LineEnd1 end if,
foreach Line = std::fromTo(LineStart, LineEnd) do
if Line = LineStart or b_false = sciLexer_api::getReadOnly(native) then
changeIndentLine(Line, IndentIncrease)
end if
end foreach,
if currentPos = anchor and 1 = getColumn(currentPos) then
gotoPos(getLineIndentPosition(LineStart))
end if
finally
endUndoAction()
end try.
Code: Select all
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
...
tryGetKeydownAction(c_Nothing, vk_tab) = tab_vip. % :- ***
...
Code: Select all
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
...
tryGetKeydownAction(c_ShiftCtl, vk_tab) = { :- vipTab := boolean::logicalNot(vipTab) }.
tryGetKeydownAction(c_Nothing, vk_tab) = if true = vipTab then tab_vip else tab end if.
...
facts
vipTab : boolean := true.
Code: Select all
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
...
tryGetKeydownAction(c_Control, vk_space) = tab.
Code: Select all
predicates
tryGetKeydownAction : (vpiDomains::keyModifier Modifier, integer VKey) -> runnable Action determ.
clauses
tryGetKeydownAction(M, K) = Fun() :-
assignedKey(M, K, Fun),
!.
......
......
facts
assignedKey : (vpiDomains::keyModifier Modifier, integer VKey, core::function_dt{core::runnable Action}) nondeterm.
clauses
% addAssignedKey(Modifier, VKey, Action) :- error on try assign "untouchable" ???
addAssignedKey(Modifier, VKey, Action) :-
% clearCmdKey(???)
retractAll(assignedKey(Modifier, VKey, _)),
assert(assignedKey(Modifier, VKey, Action)).
Code: Select all
predicates
addAssignedKey : (vpiDomains::keyModifier Modifier, integer VKey, core::function_dt{core::runnable Action}).
Code: Select all
implement main
open core, console, list
clauses
run() :-
Dlg = dialog::new(window::getActiveWindow()),
Dlg:setFont(vpi::fontCreateByName("Verdana", 22)),
Dlg:setUnit(dialog::pixelUnit),
Dlg:setModal(true),
Dlg:setDecoration(frameDecoration::titlebar([frameDecoration::closeButton])),
Dlg:setPosition(200, 100),
Dlg:setSize(600, 400),
Lexer = sciLexer::new(Dlg),
Lexer:setSize(600, 400),
Lexer:addAssignedKey(vpiDomains::c_Nothing, gui_native::vk_escape, { = Dlg:close }),
Lexer:addAssignedKey(vpiDomains::c_Control, gui_native::vk_space, { = Lexer:tab }),
Lexer:addAssignedKey(vpiDomains::c_Control, gui_native::vk_Skey,
{ = { :- Lexer:insertText("https://discuss.visual-prolog.com/") } :-
"" = string::trim(Lexer:curLine) }),
Lexer:addAssignedKey(vpiDomains::c_Control, gui_native::vk_Okey,
{ = { :- shell_api::shellOpen(Link) } :-
Link = string::trim(Lexer:curLine),
string::hasPrefix(Link, "https://", _) }),
Dlg:show().
end implement main
goal
console::runUtf8(main::run).