Page 3 of 3
Posted: 21.06.2020 15:57
by tmsg
Alexey wrote:Could you give code of plugin which uses this cmd_ and fails? it must switch to hex, to editor, and call cmd, and fail.
Look into my post from "Today 14:20" probably two hours different for your TZ. That's the code (minus the definition of hexCr

). This code works but it doesn't scroll to the caret.
Adding ed.action(EDACTION_UPDATE) either before or after the ed.cmd(cmds.cCommand_ScrollToCaretTop) call doesn't make a difference.
Posted: 21.06.2020 17:12
by Alexey
you missed PROP_LINE_TOP.
this works ok--
Code: Select all
import os
from cudatext import *
import cudatext_cmd as cmds
class Command:
cr=None
top=None
def run(self):
if ed.get_prop(PROP_V_MODE)!=VMODE_NONE:
ed.set_prop(PROP_V_MODE,VMODE_NONE)
ed.focus()
if self.top:
ed.set_prop(PROP_LINE_TOP, self.top)
if self.cr:
ed.set_caret(*self.cr)
else:
self.top=ed.get_prop(PROP_LINE_TOP)
self.cr=ed.get_carets()[0]
ed.set_prop(PROP_V_MODE,VMODE_HEX)
ed.set_prop(PROP_V_WIDTH_HEX,32)
Posted: 22.06.2020 09:12
by tmsg
@Alexey: Alright, after adding those calls it works now although I still think that the ed.cmd(cmds.cCommand_ScrollToCaretTop) call should have worked in the sense that it should scroll the caret into view (though not necessarily with the same top line). Anyway...
A side note: I think your code is not ideal as it only works with one editor being toggled. Toggling a second editor while the first is still toggled will overwrite the values from the first toggle. That's why I used a dict in my code.
Posted: 22.06.2020 10:57
by Alexey
but this plugin works as well! On Linux. will check on Win10.
Code: Select all
import os
from cudatext import *
from cudatext_cmd import *
class Command:
cr=None
top=None
def run(self):
if ed.get_prop(PROP_V_MODE)!=VMODE_NONE:
ed.set_prop(PROP_V_MODE,VMODE_NONE)
ed.focus()
#if self.top:
#ed.set_prop(PROP_LINE_TOP, self.top)
if self.cr:
ed.set_caret(*self.cr)
ed.cmd(cCommand_ScrollToCaretTop)
else:
#self.top=ed.get_prop(PROP_LINE_TOP)
self.cr=ed.get_carets()[0]
ed.set_prop(PROP_V_MODE,VMODE_HEX)
ed.set_prop(PROP_V_WIDTH_HEX,32)
Posted: 22.06.2020 11:01
by Alexey
> Toggling a second editor while the first is still toggled will overwrite the values from the first toggle.
yes, and needed more! "ed" has handle 0 - always- so saving nnn[ed] is useless, need to save REAL handle,
it is ed.get_prop -
* PROP_HANDLE_SELF: int: handle of editor object, for which get_prop is called. This handle is unique among all objects in program (it is memory address). Note that ed.h==0, it is virtual handle for the focused editor. This API returns the real handle.
* PROP_HANDLE_PRIMARY: int: handle of editor object, which is primary editor in a file tab (always visible). None for separate editors.
* PROP_HANDLE_SECONDARY: int: handle of editor object, which is secondary editor in a file tab (visible only when file tab is splitted). None for separate editors.
restore from handle: e = Editor(h)
Posted: 22.06.2020 15:06
by tmsg
Alexey wrote:yes, and needed more! "ed" has handle 0 - always- so saving nnn[ed] is useless, need to save REAL handle,
Good to know

. Code adapted.
Posted: 22.06.2020 15:13
by Alexey
checked that issue with cCommand_ on Win10, all ok there too. file is scrolled to caret after switch hex->editor.