mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-30 01:56:31 +03:00
Fix selection rectangle and letter wrap.
This commit is contained in:
@@ -94,7 +94,8 @@ class EE_API LineWrapping {
|
||||
|
||||
VisualLine getVisualLine( Int64 docIdx ) const;
|
||||
|
||||
VisualLineInfo getVisualLineInfo( const TextPosition& pos ) const;
|
||||
VisualLineInfo getVisualLineInfo( const TextPosition& pos,
|
||||
bool allowVisualLineEnd = false ) const;
|
||||
|
||||
TextRange getVisualLineRange( Int64 visualLine ) const;
|
||||
|
||||
@@ -108,7 +109,7 @@ class EE_API LineWrapping {
|
||||
|
||||
bool isUnderConstruction() const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
std::shared_ptr<TextDocument> mDoc;
|
||||
FontStyleConfig mFontStyle;
|
||||
Config mConfig;
|
||||
|
||||
@@ -466,7 +466,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
|
||||
void unregisterPlugin( UICodeEditorPlugin* plugin );
|
||||
|
||||
virtual Vector2f getTextPositionOffset( const TextPosition& pos,
|
||||
std::optional<Float> lineHeight = {} ) const;
|
||||
std::optional<Float> lineHeight = {},
|
||||
bool allowVisualLineEnd = false ) const;
|
||||
|
||||
Vector2f getTextPositionOffsetSanitized( TextPosition pos,
|
||||
std::optional<Float> lineHeight = {} ) const;
|
||||
|
||||
@@ -103,7 +103,7 @@ LineWrapping::LineWrapInfo LineWrapping::computeLineBreaks( const String& string
|
||||
info.wraps.push_back( lastSpace + 1 );
|
||||
xoffset = w + info.paddingStart + ( xoffset - lastWidth );
|
||||
} else {
|
||||
info.wraps.push_back( idx + 1 );
|
||||
info.wraps.push_back( idx );
|
||||
xoffset = w + info.paddingStart;
|
||||
}
|
||||
lastSpace = 0;
|
||||
@@ -186,7 +186,7 @@ LineWrapping::LineWrapInfo LineWrapping::computeLineBreaks( const TextDocument&
|
||||
info.wraps.push_back( lastSpace + 1 );
|
||||
xoffset = w + info.paddingStart + ( xoffset - lastWidth );
|
||||
} else {
|
||||
info.wraps.push_back( idx + 1 );
|
||||
info.wraps.push_back( idx );
|
||||
xoffset = w + info.paddingStart;
|
||||
}
|
||||
lastSpace = 0;
|
||||
@@ -340,7 +340,8 @@ LineWrapping::VisualLine LineWrapping::getVisualLine( Int64 docIdx ) const {
|
||||
return line;
|
||||
}
|
||||
|
||||
LineWrapping::VisualLineInfo LineWrapping::getVisualLineInfo( const TextPosition& pos ) const {
|
||||
LineWrapping::VisualLineInfo LineWrapping::getVisualLineInfo( const TextPosition& pos,
|
||||
bool allowVisualLineEnd ) const {
|
||||
if ( mConfig.mode == LineWrapMode::NoWrap ) {
|
||||
LineWrapping::VisualLineInfo info;
|
||||
info.visualIndex = pos.line();
|
||||
@@ -352,8 +353,9 @@ LineWrapping::VisualLineInfo LineWrapping::getVisualLineInfo( const TextPosition
|
||||
LineWrapping::VisualLineInfo info;
|
||||
for ( Int64 i = fromIdx; i < toIdx; i++ ) {
|
||||
Int64 fromCol = mWrappedLines[i].column();
|
||||
Int64 toCol =
|
||||
i + 1 <= toIdx ? mWrappedLines[i + 1].column() - 1 : mDoc->line( pos.line() ).size();
|
||||
Int64 toCol = i + 1 <= toIdx
|
||||
? mWrappedLines[i + 1].column() - ( allowVisualLineEnd ? 0 : 1 )
|
||||
: mDoc->line( pos.line() ).size();
|
||||
if ( pos.column() >= fromCol && pos.column() <= toCol ) {
|
||||
info.visualIndex = i;
|
||||
info.range = { { pos.line(), fromCol }, { pos.line(), toCol } };
|
||||
|
||||
@@ -2080,10 +2080,11 @@ void UICodeEditor::setScrollY( const Float& val, bool emmitEvent ) {
|
||||
}
|
||||
|
||||
Vector2f UICodeEditor::getTextPositionOffset( const TextPosition& position,
|
||||
std::optional<Float> lineHeight ) const {
|
||||
std::optional<Float> lineHeight,
|
||||
bool allowVisualLineEnd ) const {
|
||||
Float lh = lineHeight ? *lineHeight : getLineHeight();
|
||||
if ( mLineWrapping.isWrappedLine( position.line() ) ) {
|
||||
auto info = mLineWrapping.getVisualLineInfo( position );
|
||||
auto info = mLineWrapping.getVisualLineInfo( position, allowVisualLineEnd );
|
||||
if ( mFont && !mFont->isMonospace() ) {
|
||||
const auto& line = mDoc->line( position.line() ).getText();
|
||||
auto partialLine =
|
||||
@@ -3580,9 +3581,9 @@ UICodeEditor::getTextRangeRectangles( const TextRange& range, const Vector2f& st
|
||||
auto nextInfo = mLineWrapping.getDocumentLine( visibleIdx + 1 );
|
||||
if ( nextInfo.line() == info.line() ) {
|
||||
endOffset =
|
||||
getTextPositionOffset( { info.line(), nextInfo.column() - 1 }, lh );
|
||||
getTextPositionOffset( { info.line(), nextInfo.column() }, lh, true );
|
||||
} else {
|
||||
endOffset = getTextPositionOffset( mDoc->endOfLine( { ln, 0 } ), lh );
|
||||
endOffset = getTextPositionOffset( mDoc->endOfLine( { ln, 0 } ), lh, true );
|
||||
}
|
||||
}
|
||||
selRect.Right = startScroll.x + endOffset.x;
|
||||
|
||||
Reference in New Issue
Block a user