When user presses Enter key in wxStyledTextCtrl
, it seems that the cursor always goes to beginning of the line (zero indentation), which is most likely the expected behavior.
I want to be able to write Script code with the following format, with line indents.
for i=1,10 do --say there is no indentation
i=i+1 -- now there is indentation via tab key
-- pressing enter should proceed with this level of indentation
print(i) -- same level of indentation with the previous code line
end
I use the following C++ code to be able to control indentation at a very basic level.
void Script::OnKeyUp(wxKeyEvent& evt)
{
if ((evt.GetKeyCode() == WXK_RETURN || evt.GetKeyCode() == WXK_NUMPAD_ENTER)) {
long int col, line;
PositionToXY(GetInsertionPoint(), &col, &line);
int PreviousIndentation = GetLineIndentation(line-1);
SetLineIndentation(line, PreviousIndentation);
GotoPos(GetCurrentPos() + PreviousIndentation);
}
}
The above C++ code preserves the indentation level, however, the cursor first goes to the beginning of the line and then to the indentation level. When using other IDEs, this does not happen in such way, such as going to the beginning of line and then to the indentation level. Rather, the cursor immediately goes to /follows the indentation level. Is there a way that the cursor can immediately go to the indentation level without initially going to zero indentation level.
By the way, I tried EVT_STC_CHARADDED
, which seems like the way implemented in ZeroBraneStudio, but when Enter key is pressed evt.GetKeyCode()
returns a weird integer and evt.GetUnicodeKey
returns \0
and moreover EVT_STC_CHARADDED
event is called twice (I guess due to CR+LF).
By the way, I am using wxWidgets-3.1.0 on Windows 10.
Any ideas would be appreciated.