Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

SyntaxEdit and tabs

A customer posted this to my forum:

I'm pretty OCD about indenting and white space. Indenting helps me keep track of opening and closing tags.

Today for the first time I noticed a problem in the editor. Indenting one line works as expected, I get a tab char for every time I press the "tab" key.

However, if I select multiple lines that all start at the left edge, I get a tab char the first time and just spaces after that.

Then it gets goofier. If I uncheck "smart indent", then I get just spaces for tab and ctrl tab, even tho "Use tab char" is checked.

And I don't understand why a tab would get me tab characters, but ctrl tab would move back one space at a time. I think something has changed in the editor.

I suppose my first question would be how do I get sedIndent to indent several selected lines (or just one line with no selected text) using tab characters instead of spaces when vsUseTabs is set? sedTabOrIndent works if no text is selected but selecting several lines to indent and then using sedTabOrIndent deletes the selection and replaces it with a tab character.



  • 5 Comments sorted by Votes Date Added
  • Posts: 0 Accepted Answer Vote Up1Vote Down
    Albert, we do something similar by using a menu item on both the main menu and a popup triggered by a right-click. The user selects a series of lines, right clicks, and clicks the menu item. Then we:
    1. Save the cursor position
    2. Get start and end of the selection span
    3. Issue BeginCompoundEdit
    4. Use a for loop to alter each line - in your case insert a tab or spaces at the start
    5. Issue EndCompoundEdit
    6. Restore the cursor position

    It works fine and is ismple for users (and us).

    Does that help?

    John C
  • Hi,

    I also can't understand, how your user was able to ident several selected lines. Because, editor just deletes selection in this case, as can be seen from TLMDCustomEditView.UI_IndentOrTab source code:

    if ((Off <> -1) and (Off < CursorOffset)) or (Ln = 0) or SelAvail then
          InvokeCommand(sedTab, false)
  • I think because I am using this:

    void __fastcall TCSEQEForm::LMDEdit1BeforeCommand(TObject *Sender, TLMDEditCommand &ACommand, Variant &/* Arg */, bool &/* AllowExec */) {

     if (((TLMDEditView *)(Sender))->SelAvail) {
      if ( (ACommand==sedTab) || (ACommand==sedTabOrIndent) || (ACommand==sedIndentToPrevIndent) || (ACommand==sedIndent) ) ACommand=((p->iface->flags4)&IFACE4FLAGSMARTINDENT) ? sedIndentToPrevIndent : sedIndent;
      else if ( (ACommand==sedUnIndent) || (ACommand==sedUnIndentToPrevIndent) ) ACommand=((p->iface->flags4)&IFACE4FLAGSMARTINDENT) ? sedUnIndentToPrevIndent : sedUnIndent;

      if ( ( (ACommand==sedIndentToPrevIndent) || (ACommand==sedIndent) ) && isShiftKeyDown() ) { // new 2010-05-04 - if Shift key is down - change to unindent
       if (ACommand==sedIndentToPrevIndent) ACommand=sedUnIndentToPrevIndent; // bug fix 2015-01-15 - changed "ACommand==" to "ACommand="
       else if (ACommand==sedIndent) ACommand=sedUnIndent; // bug fix 2015-01-15 - changed "ACommand==" to "ACommand="
  • So can anything be done to use tabs better when vsUseTabs is set when indenting? Perhaps the editor can take all the space and tab characters at the beginning of the line and change it to tabs and space characters (using space characters only if needed because a tab would be too big)... or perhaps this is getting too complicated?
  • edited June 2016 Posts: 134Vote Up0Vote Down
    Hi John,

    I'm sorry for the delay. Your suggestion sounds good. I'll try it out today, Thanks!

    UPDATE: It worked well! I am now adding the tabs to each line and taking them away when unindenting (or an equivalent number of spaces if possible). I'm not saving or restoring the cursor position or calling BeginCompoundEdit or EndCompoundEdit because I am just getting the selected text, processing it, then setting it back with Edit->SelectedText=newlines (each line ends in a CRLF). Thanks again for the idea.
Sign In or Register to comment.