best way to edit lines in ymacs?

4 views
Skip to first unread message

Joe

unread,
Feb 17, 2010, 9:55:53 AM2/17/10
to Ymacs - AJAX code editor
I found how to get the line of the mark:
var mr = this.markMarker.getRowCol().row;

So now what is the best way to edit lines? for example, if I want to
go though a group of lines and apply substr() or replace() on them.

I tried:
// no workie
this.code[i] = this.code[i].replace(regex,"");

// works, but it seems to get ymacs confused:
this._replaceLine(i,this.code[i].substr(toremove));
or
this._replaceLine(i,this.code[i].replace(regex,""));;

thanks,
-joe

Mihai Călin Bazon

unread,
Feb 19, 2010, 2:06:07 PM2/19/10
to ym...@googlegroups.com
Indeed, _replaceLine should not be used directly.. The way to go is
via insert and delete commands. Either:

this.cmd("delete_region", begin, end);
this.cmd("goto_char", position_for_insertion);
this.cmd("insert", text_to_insert);

Or the more direct (these should be public API in fact):

this._deleteText(begin, end);
this._insertText(text_to_insert, position_for_insertion);
this._replaceText(begin, end, replacement_text);

It's pretty awkward to use these for line-by-line changes, but you can
do this instead:

var text = this._bufferSubstring(begin, end);
var new_text = do_something_on(text);
this._replaceText(begin, end, new_text);

HTH.

-Mihai

> --
> www.ymacs.com - AJAX code editor

--
Mihai Bazon,
http://mihai.bazon.net/blog

Reply all
Reply to author
Forward
0 new messages