Author Topic: _QROffset () trouble  (Read 3725 times)

Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
_QROffset () trouble
« on: June 20, 2007, 03:17:46 pm »
I have the code below which inserts some text. My problem is that I insert the text before the current offset, so the originalOffset is no longer valid? How can I go around that? I tried adding the length (indent_string (p_SyntaxIndent)) + length (inserted text), but still not any near to the original offset :-\. Also how could I possibly merge the insert_blank_line_below and the _insert_text into 1 transaction (1 undo operation). Thanks in advance.

Code: [Select]
// generates a field prefixed with "_" from a local variable just after the class definition
//
static _str generate_field_from_local (VS_TAG_BROWSE_INFO varInfo)
{
   long originalOffset = _QROffset ();

   _str lineText;
   VS_TAG_BROWSE_INFO classInfo;

   if (get_class_context (originalOffset, classInfo) < 0)
      return null;

   p_line = classInfo.scope_line_no;
   get_line (lineText);
   if (!endsWith (lineText, "{"))// opening { not on the same line of the class definition
      p_line++; // assuming opening { is on the next line, so move to there

   insert_blankline_below (); // this also indents
   p_line++;

   _str fieldName = "_" :+ varInfo.member_name;
   _str field = "private " :+ varInfo.return_type :+ " " :+ fieldName :+ ";";
   _insert_text (field);
   _GoToROffset (originalOffset); // restore offset
   return fieldName;
}
« Last Edit: June 20, 2007, 03:19:44 pm by i-nZ »

hs2

  • Senior Community Member
  • Posts: 2749
  • Hero Points: 289
Re: _QROffset () trouble
« Reply #1 on: June 20, 2007, 03:56:56 pm »
@i-nZ: What about using _save/_restore_pos ? Did you already try it ?
Code: [Select]
   typeless p;
   _save_pos2(p);

   // do stuff maybe modifying the buffer

   _restore_pos2(p);

Alternatively unnamed boookmarks can be used too:
Code: [Select]
   push_bookmark();

   // ...

   pop_bookmark();

Sorry, no idea about undo compression :(

HS2

Ivan N. Zlatev

  • Community Member
  • Posts: 87
  • Hero Points: 5
Re: _QROffset () trouble
« Reply #2 on: June 20, 2007, 04:11:35 pm »
Hey, thanks for the tips. I wasn't aware of the existance of the bookmarks/positions functions. Thanks again.