Merge branch 'main' of https://github.com/evennia/evennia into editor_search_traceback

This commit is contained in:
Chiizujin 2024-04-07 22:06:14 +10:00
commit c21c5667c9
25 changed files with 503 additions and 188 deletions

View file

@ -98,7 +98,7 @@ _HELP_TEXT = _(
:s <l> <w> <txt> - search/replace word or regex <w> in buffer or on line <l>
:j <l> <w> - justify buffer or line <l>. <w> is f, c, l or r. Default f (full)
:f <l> - flood-fill entire buffer or line <l>: Equivalent to :j left
:f <l> - flood-fill entire buffer or line <l>. Equivalent to :j <l> l
:fi <l> - indent entire buffer or line <l>
:fd <l> - de-indent entire buffer or line <l>
@ -351,6 +351,35 @@ class CmdEditorBase(_COMMAND_DEFAULT_CLASS):
self.arg1 = arg1
self.arg2 = arg2
def insert_raw_string_into_buffer(self):
"""
Insert a line into the buffer. Used by both CmdLineInput and CmdEditorGroup.
"""
caller = self.caller
editor = caller.ndb._eveditor
buf = editor.get_buffer()
# add a line of text to buffer
line = self.raw_string.strip("\r\n")
if editor._codefunc and editor._indent >= 0:
# if automatic indentation is active, add spaces
line = editor.deduce_indent(line, buf)
buf = line if not buf else buf + "\n%s" % line
self.editor.update_buffer(buf)
if self.editor._echo_mode:
# need to do it here or we will be off one line
cline = len(self.editor.get_buffer().split("\n"))
if editor._codefunc:
# display the current level of identation
indent = editor._indent
if indent < 0:
indent = "off"
self.caller.msg("|b%02i|||n (|g%s|n) %s" % (cline, indent, raw(line)))
else:
self.caller.msg("|b%02i|||n %s" % (cline, raw(line)))
def _load_editor(caller):
"""
@ -394,29 +423,7 @@ class CmdLineInput(CmdEditorBase):
If the editor handles code, it might add automatic
indentation.
"""
caller = self.caller
editor = caller.ndb._eveditor
buf = editor.get_buffer()
# add a line of text to buffer
line = self.raw_string.strip("\r\n")
if editor._codefunc and editor._indent >= 0:
# if automatic indentation is active, add spaces
line = editor.deduce_indent(line, buf)
buf = line if not buf else buf + "\n%s" % line
self.editor.update_buffer(buf)
if self.editor._echo_mode:
# need to do it here or we will be off one line
cline = len(self.editor.get_buffer().split("\n"))
if editor._codefunc:
# display the current level of identation
indent = editor._indent
if indent < 0:
indent = "off"
self.caller.msg("|b%02i|||n (|g%s|n) %s" % (cline, indent, raw(line)))
else:
self.caller.msg("|b%02i|||n %s" % (cline, raw(line)))
self.insert_raw_string_into_buffer()
class CmdEditorGroup(CmdEditorBase):
@ -806,6 +813,9 @@ class CmdEditorGroup(CmdEditorBase):
caller.msg(_("Auto-indentation turned off."))
else:
caller.msg(_("This command is only available in code editor mode."))
else:
# no match - insert as line in buffer
self.insert_raw_string_into_buffer()
class EvEditorCmdSet(CmdSet):