Search code examples
c#visual-studiomef

How to check if text editor view in Visual Studio is modified (unsaved)?


In order to trigger autocompletion I need to know which text view among opened ones does contain modified text (i.e. not yet saved to disk). How can I check that having IVsTextView and ITextView instances?


Solution

  • I've found the following solution:

    IVsTextLines buffer;
    if (vsTextView.GetBuffer(out buffer) != VSConstants.S_OK)
    {
        return false;
    }
    
    uint flags;
    buffer.GetStateFlags(out flags);
    bool isDirty = (flags & (uint)BUFFERSTATEFLAGS.BSF_MODIFIED) != 0;