Do not switch/steal focus when using the editor scrollbars (SpartanJ/ecode#626).

This commit is contained in:
Martín Lucas Golini
2025-09-08 13:56:21 -03:00
parent 7e6de3f9b2
commit 428730c3fb
3 changed files with 28 additions and 5 deletions

View File

@@ -287,6 +287,8 @@ class EE_API TextDocument {
std::size_t getLineLength( Int64 ) const;
void safeLineOp( Int64 line, std::function<void(TextDocumentLine&)> op );
void getLineTextToBuffer( Int64 line, String& buffer ) const;
std::string getLineTextUtf8( Int64 line ) const;

View File

@@ -1727,6 +1727,16 @@ std::size_t TextDocument::getLineLength( Int64 line ) const {
return line >= (Int64)mLines.size() ? 0 : mLines[line].size();
}
void TextDocument::safeLineOp( Int64 line, std::function<void( TextDocumentLine& )> op ) {
Lock l( mLinesMutex );
static TextDocumentLine safeLine = TextDocumentLine( "", nullptr );
if ( line >= 0 && line < mLines.size() ) {
op( mLines[line] );
} else {
op( safeLine );
}
}
String TextDocument::getLineText( Int64 line ) const {
// eeASSERT( line < (Int64)linesCount() );
Lock l( mLinesMutex );

View File

@@ -714,8 +714,15 @@ void UICodeEditor::onFoldRegionsUpdated( size_t oldCount, size_t newCount ) {
}
Uint32 UICodeEditor::onMessage( const NodeMessage* msg ) {
if ( msg->getMsg() == NodeMessage::MouseDown )
if ( msg->getMsg() == NodeMessage::MouseDown ) {
return 1;
} else if ( msg->getMsg() == NodeMessage::Focus ) {
if ( msg->getSender() == mVScrollBar || msg->getSender() == mHScrollBar ||
mVScrollBar->isParentOf( msg->getSender() ) ||
mHScrollBar->isParentOf( msg->getSender() ) ) {
setFocus();
}
}
return UIWidget::onMessage( msg );
}
@@ -5194,11 +5201,15 @@ bool UICodeEditor::checkAutoCloseXMLTag( const String& text ) {
}
Int64 UICodeEditor::getCurrentColumnCount() const {
Int64 curLine = mDoc->getSelection().start().line();
Int64 sel = mDoc->getSelection().start().column();
Int64 count = 0;
for ( Int64 i = 0; i < sel; i++ )
count += mDoc->line( curLine ).getText()[i] == '\t' ? mTabWidth : 1;
mDoc->safeLineOp(
mDoc->getSelection().start().line(), [this, &count]( TextDocumentLine& line ) {
const String& lineText = mDoc->line( mDoc->getSelection().start().line() ).getText();
Int64 lineLen = lineText.size();
Int64 sel = eemin( mDoc->getSelection().start().column(), lineLen );
for ( Int64 i = 0; i < sel; i++ )
count += lineText[i] == '\t' ? mTabWidth : 1;
} );
return count;
}