Is there a way to display the current cursor position in Komodo Edit? I frequently work with binary files and need to update pointers after edits. It would be great to have this displayed with the line and column info or assign a macro to a hot key to display this elsewhere. Any ideas? I am new to Komodo and love it.
The current line and cursor position (as well as the current selection) are displayed at the bottom right of Komodo, in the status bar.
Thanks for the reply.
For clarification - I need the position from the top of the file not just the current line and column. My editor is only displaying line and column values and I would like to get it to display the absolute position from the top of the file. If I select everything from the top of the file to the position I would like to know, the editor will display the number of selected characters “ch”. This method works for very small files but when the file is a few thousand lines it is a real pain in the …
I was able to get something close as a Macro assigned to a key.
komodo.assertMacroVersion(3);
var out = "echo " + komodo.editor.currentPos;
if (komodo.view && komodo.view.scintilla) {
komodo.view.scintilla.focus();
ko.run.runEncodedCommand(window, out);
}
However, the files I am working with contain some 2-byte characters and the function returns the number of bytes not the number of characters. I need the number of characters.
Any other Ideas???
Hmm, from a bit of googling the following 2 topics seem relevant:
- https://groups.google.com/forum/#!topic/scintilla-interest/1HDFaCFUvXQ
- http://stackoverflow.com/questions/4492171/scintilla-how-do-you-find-the-byte-position-given-a-specific-character-position
Based on that I’m guessing it is not possible, at least not without getting creative with the scintilla API.
I think the simplest solution will involve use of a Komodo macro:
var sm = ko.views.manager.currentView.scimoz;
// Get character length:
var msg = "Length: " + sm.getTextRange(0, sm.currentPos).length;
// Get byte length:
//var msg = "Length: " + sm.currentPos;
// Use statusbar to show where you are:
ko.statusBar.AddMessage(msg, "find", 5000, true);
Thanks toddw, that worked perfectly.
I combined your code with my previous so the “Length” displays in the Command Output window. I wanted to keep it displayed as I need to be able to move around within the file and reference the value several times.
Thanks again for everyone’s help!
komodo.assertMacroVersion(3);
var sm = ko.views.manager.currentView.scimoz
var msg = "Echo Position: " + sm.getTextRange(0,sm.currentPos).length;
if (komodo.view && komodo.view.scintilla) {
komodo.view.scintilla.focus();
ko.run.runEncodedCommand(window, msg);
}
Hey JustMe,
I wrote up a macro that will update your statusbar Ln:Col: section with either the current byte position or character position of your cursor in the doc. I’ve blogged about it here: Add byte or char pos to statusbar. The installation instructions are at the bottom of the blog.
I hope that’s useful to you.
-
Carey