Why is Scintilla doing this?

42 views
Skip to first unread message

Andrew Truckle

unread,
May 5, 2024, 2:02:33 PMMay 5
to scintilla-interest
Here is my saving code:

Scintilla::Position nBytesToWrite{ m_edit.GetLength() };
const char* CharacterPointer = m_edit.GetCharacterPointer();
while (nBytesToWrite > 0)
{
Scintilla::Position nDataToWrite{ nBytesToWrite };
if (nDataToWrite > UINT_MAX)
nDataToWrite = UINT_MAX;
#pragma warning(suppress: 26472)
file.Write(CharacterPointer, static_cast<UINT>(nDataToWrite));

// Prepare for the next loop around
#pragma warning(suppress: 26481)
CharacterPointer += nDataToWrite;
nBytesToWrite -= nDataToWrite;
}




It works  really well. But I have two annoying side effects:

  1. It selects all the text.
  2. It scrolls all the way to the bottom.
I don't want it to do any of this. The cursor should stay where it was and it shouldn't select all the text.

Why is it doing this?

Andrew Truckle

unread,
May 5, 2024, 3:39:26 PMMay 5
to scintilla-interest
Firstly, I apologise by my wording "why is scintilla doing this". That was a bold assumption!

Upon closer inspecting I can confirm that saving an existing file does as it should. Cursor says in the same place and nothing gets selected.

It is when I show my file dialog and then click either OK or cancel that this issue happens.

Andrew Truckle

unread,
May 5, 2024, 4:28:10 PMMay 5
to scintilla-interest
If I call this before showing the file dialog:

const auto line = m_edit.GetFirstVisibleLine();
const auto pos = m_edit.GetCurrentPos();

And then at the end, wther they click OK or cancel to that dialog, I call:

m_edit.SetFirstVisibleLine(line);
m_edit.SetCurrentPos(pos);
m_edit.ClearSelections();

It works. Position stays the file, nothing selected. But the caret is right at the start of the document.

If I swap the lines:

m_edit.SetFirstVisibleLine(line);
m_edit.ClearSelections();
m_edit.SetCurrentPos(pos);

The caret ends up at the right place, but now everything is selected from the start of the document to the caret.

I can't win.

Is there no way to get the editor to temporarily stop doing anything ?

Tried SetRedraw with false and true and it didn't quite work.

Neil Hodgson

unread,
May 5, 2024, 5:53:24 PMMay 5
to scintilla...@googlegroups.com
Andrew Truckle:

> It selects all the text.
> It scrolls all the way to the bottom.
>
> I don't want it to do any of this. The cursor should stay where it was and it shouldn't select all the text.
>...
> It is when I show my file dialog and then click either OK or cancel that this issue happens.

I don't think this is caused by Scintilla but by your application or
framework.SciTE doesn't do this for File | Save As ; Cancel.

Neil

Andrew Truckle

unread,
May 5, 2024, 5:56:59 PMMay 5
to scintilla-interest
I thought so too. It has been suggested that I try to use Spy. I'll do that tomorrow. But I think my only solution is to try and return to the state it was before the save:

scroll position
caret position
selected state - or non if easiest.

so I can get the scroll position right with setfirstvisible line.
and I get set the caret position right with setcurrentpos.

But when I clesr selections the caret return to top of file.

Andrew Truckle

unread,
May 6, 2024, 9:42:15 AMMay 6
to scintilla-interest
I have atleast improved it by doing:

Set first visible line
Set current pos
Set anchor pos

Then it looks like it did before showing the File dialog.

So I will stick with that.

Andrew Truckle

unread,
May 8, 2024, 3:27:01 PMMay 8
to scintilla-interest
For your info, I ended up doing this as the resolution:

UINT CMyScintillaCtrl::OnGetDlgCode()
{
// Return default value, removing the DLGC_HASSETSEL flag
return (__super::OnGetDlgCode() & ~DLGC_HASSETSEL);
}

Reply all
Reply to author
Forward
0 new messages