Sublime Forum

Running "goto_row_col" command in custom plugin

#1

All,

I am trying to run some commands in my custom plugin. It runs fine except for 1 task: move the cursor to a specific position.

I used “goto_row_col” command to move the cursor to a specific position (e.g. move the cursor to 1st Column on Row 1 in this example). But, this does not work.

self.window.active_view().run_command(“goto_row_col”,{“row”: 1, “col”: 1})

If I try to run below to delete a line, it works.

self.window.active_view().run_command(“run_macro_file”, {“file”: “res://Packages/Default/Delete Line.sublime-macro”})

So, I would assume that something after “run_command” is incorrect, but I don’t know what to change.

Thank you very much for your help in advance.

0 Likes

How to do the `jump_back` command from find panel?
#2

Sublime Text does not seem to have a command like goto_row_col. It seems to be from a package for Sublime Text 2:

  1. https://packagecontrol.io/packages/GotoRowCol

If you want to place the cursor at some specific position just to do

view.sel().clear(); view.sel().add(0);

But the view is not updating automatically. Then to overcome this it would only be enough to use:

view.sel().clear(); view.sel().add(0); bug = [s for s in view.sel()]; view.add_regions("bug", bug, "bug", "dot", sublime.HIDDEN | sublime.PERSISTENT); view.erase_regions("bug"); 

References:

  1. https://www.sublimetext.com/docs/3/api_reference.html
  2. Plugin new selection does not always get updated properly
  3. ST2 & ST3: View is not updated after adding new Region
0 Likes

#3

If you change the selection you may want to use a TextCommand and then view.sel().clear(); view.sel().add(0); should work. As far I know the soft-undo does not work, if you use a WindowCommand to change the selection.

1 Like

#4

Thank you, addons_zz. It worked perfectly!!!

1 Like

#5

Thank you, r-stein. It worked perfectly!!!

1 Like