Fix editor multiline copy.

This commit is contained in:
Jonas 'Sortie' Termansen 2016-03-06 00:49:55 +01:00
parent a0c61a53e1
commit 0705fabd6d
1 changed files with 9 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen. * Copyright (c) 2013, 2014, 2016 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -749,6 +749,7 @@ void editor_type_copy(struct editor* editor)
for ( size_t row = start_row, column = start_column; for ( size_t row = start_row, column = start_column;
is_row_column_lt(row, column, end_row, end_column); ) is_row_column_lt(row, column, end_row, end_column); )
{ {
struct line* line = &editor->lines[row];
if ( row == end_row ) if ( row == end_row )
{ {
length += end_column - column; length += end_column - column;
@ -756,7 +757,7 @@ void editor_type_copy(struct editor* editor)
} }
else else
{ {
length += editor->lines[row].used + 1 /*newline*/; length += (line->used - column) + 1 /*newline*/;
column = 0; column = 0;
row++; row++;
} }
@ -770,15 +771,17 @@ void editor_type_copy(struct editor* editor)
struct line* line = &editor->lines[row]; struct line* line = &editor->lines[row];
if ( row == end_row ) if ( row == end_row )
{ {
memcpy(editor->clipboard + offset, line->data + column, sizeof(wchar_t) * (end_column - column)); memcpy(editor->clipboard + offset, line->data + column,
sizeof(wchar_t) * (end_column - column));
offset += end_column - column; offset += end_column - column;
column = end_column; column = end_column;
} }
else else
{ {
memcpy(editor->clipboard + offset, line->data, sizeof(wchar_t) * line->used); memcpy(editor->clipboard + offset, line->data + column,
editor->clipboard[offset + line->used] = L'\n'; sizeof(wchar_t) * (line->used - column));
offset += line->used + 1 /*newline*/; editor->clipboard[offset + (line->used - column)] = L'\n';
offset += (line->used - column) + 1 /*newline*/;
column = 0; column = 0;
row++; row++;
} }