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.
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)
@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.
> 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.