Skip to content

Commit

Permalink
Fix multiline selection crash (#120)
Browse files Browse the repository at this point in the history
Also fix multiline drag-n-drop to same lines
  • Loading branch information
JohnDTill committed Jul 23, 2023
1 parent d8916bb commit 88b4dfd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/typeset_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,12 @@ std::string Selection::selectedLines() const{
out.resize(serial_chars);
size_t curr = 0;

for(Text* t = tL; t != lL->back(); t = t->nextTextAsserted()){
t->writeString(out, curr, iL);
tL->writeString(out, curr, iL);
for(Text* t = tL; t != lL->back();){
t->nextConstructAsserted()->writeString(out, curr);
t = t->nextTextAsserted();
t->writeString(out, curr);
}
lL->back()->writeString(out, curr, iL);
out[curr++] = '\n';

for(Line* l = lL->nextAsserted(); l != lR; l = l->nextAsserted()){
Expand All @@ -384,7 +385,6 @@ std::string Selection::selectedLines() const{
t->writeString(out, curr);
t->nextConstructAsserted()->writeString(out, curr);
}

tR->writeString(out, curr, 0, iR);

return out;
Expand Down
25 changes: 23 additions & 2 deletions src/typeset_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,31 @@ void View::resolveSelectionDrag(double x, double y){

if(controller.contains(x, y)) return;

model->premutate();
std::string str = controller.selectedText();
Command* a = controller.deleteSelection();
bool delete_first = x <= controller.xActive();
bool delete_first = (x <= controller.xActive());
if(!controller.isPhraseSelection()){
Line* line_bot;
Line* line_top;
if(controller.isForward()){
line_top = controller.anchorLine();
line_bot = controller.activeLine();
}else{
line_top = controller.activeLine();
line_bot = controller.anchorLine();
}
if(y < line_top->y){
delete_first = false;
}else if(y > line_bot->yBottom()){
delete_first = true;
}else if (y < line_top->yBottom() && x <= controller.xActive()){
delete_first = true;
}else if (y >= line_bot->y && x > controller.xActive()){
delete_first = true;
}else{
return;
}
}
if(delete_first) a->redo(controller);
Line* l = model->nearestLine(y);
controller.clickTo(l, x, y);
Expand Down

0 comments on commit 88b4dfd

Please sign in to comment.