2022-05-20 00:42:30 +00:00
|
|
|
use editor::{ClipboardSelection, Editor};
|
|
|
|
use gpui::{ClipboardItem, MutableAppContext};
|
|
|
|
|
|
|
|
pub fn copy_selections_content(editor: &mut Editor, linewise: bool, cx: &mut MutableAppContext) {
|
2022-05-24 20:35:57 +00:00
|
|
|
let selections = editor.selections.all_adjusted(cx);
|
2022-05-20 00:42:30 +00:00
|
|
|
let buffer = editor.buffer().read(cx).snapshot(cx);
|
|
|
|
let mut text = String::new();
|
|
|
|
let mut clipboard_selections = Vec::with_capacity(selections.len());
|
|
|
|
{
|
|
|
|
for selection in selections.iter() {
|
|
|
|
let initial_len = text.len();
|
|
|
|
let start = selection.start;
|
|
|
|
let end = selection.end;
|
|
|
|
for chunk in buffer.text_for_range(start..end) {
|
|
|
|
text.push_str(chunk);
|
|
|
|
}
|
|
|
|
clipboard_selections.push(ClipboardSelection {
|
|
|
|
len: text.len() - initial_len,
|
|
|
|
is_entire_line: linewise,
|
2022-07-29 05:34:56 +00:00
|
|
|
first_line_indent: buffer.indent_size_for_line(start.row).len,
|
2022-05-20 00:42:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cx.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
|
|
|
|
}
|