Menu

#1850 Filled in virtual space does not respect SCI_SETUSETABS

Feature_Request
closed-fixed
5
2016-09-05
2016-08-04
No

Currently virtual space is filled in only by spaces even if SCI_SETUSETABS(true) is called.

I would like to see this work a bit more like SCI_SETINDENT, where it actually uses tabs if needed.

In the first case (x = virtual space, | = caret)

int main(void){
xxxxxx|
}

Would behave exactly like SCI_SETINDENT and use a single tab and 2 spaces to fill in the virtual space. (this assumes tabwidth is 4)

The other case of:

int main(void){
    int x = 0;xxxxxxxxxx|
}

Then the virtual space would be filled in by spaces only (which is the current behavior)

Related

Bugs: #1456

Discussion

  • Justin Dailey

    Justin Dailey - 2016-08-11

    Not being familiar with the code I took a crack and it really isn't too difficult to (mostly) implement it. There are just some corner cases that would have to be handled...for example multiple cursors on the same line, etc.

    The reason this would be quite useful is I enjoy how MSVC handles auto-indentation. It actually uses virtual space instead of going ahead and sticking in whitespace...it only actuall fills it in if you type something. Saves alot of purely whitespace-filled lines.

     
  • Neil Hodgson

    Neil Hodgson - 2016-08-12
    • labels: --> scintilla, indentation, virtualspace
    • status: open --> open-accepted
    • assigned_to: Neil Hodgson
     
  • Neil Hodgson

    Neil Hodgson - 2016-08-12

    Using space for cases where there is only whitespace before on the line appears worthwhile. If there are visible characters before the caret then only spaces should be used.

    For the case with multiple cursors on one line, this will be a rare case, so I think its fine to behave arbitrarily with no guarantee of maximum use of tabs.

    This should be tested with cases where there is already realized whitespace, which may be a mixture of spaces and tabs, along with virtual space.

     
  • Justin Dailey

    Justin Dailey - 2016-08-12

    This is my attempt at a patch (just a single function updated), not sure you you prefer to get code changes. As I stated it doesn't handle multiple cursors on the same line. Since it uses SetLineIndentation() it gracefully handles the case where there is whitespace + virtual space before the cursor.

    int Editor::InsertSpace(int position, unsigned int spaces) {
        if (spaces > 0) {
            const int line = pdoc->LineFromPosition(position);
            const int indent = pdoc->GetLineIndentPosition(line);
            if (indent == position) {
                pdoc->SetLineIndentation(line, pdoc->GetLineIndentation(line) + spaces);
                return pdoc->LineEnd(line);
            }
            else {
                std::string spaceText(spaces, ' ');
                const int lengthInserted = pdoc->InsertString(position, spaceText.c_str(), spaces);
                position += lengthInserted;
            }
        }
        return position;
    }
    
     
  • Neil Hodgson

    Neil Hodgson - 2016-08-14

    While the change may be OK, its called from 10 different places which may have slightly different expectations, so I'm wary and it will take a while to check.

     
  • Neil Hodgson

    Neil Hodgson - 2016-08-31
    • status: open-accepted --> open-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2016-08-31

    Since this is only called when the second argument is for virtual space, renamed the method to RealizeVirtualSpace and added an overload that takes and returns a SelectionPosition to allow tighter bundling of the position elements. Also returning the result of SetLineIndentation as this is more robust if SetLineIndentation is changed and its also less code.
    Committed as [19b88d].

     

    Related

    Commit: [19b88d]

  • Neil Hodgson

    Neil Hodgson - 2016-09-05
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.