Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
Fix pasting multiline code in single-lined text area (#1348)
Browse files Browse the repository at this point in the history
When pasting multiline code in a single-lined text area, only the first line will be inserted.
  • Loading branch information
s9ferech authored Mar 23, 2021
1 parent 3b30871 commit a59a3b5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
- [Disable area selection][1318]. The area selection was visible despite being
non-functional. To avoid confusion, area selection has been disabled until it
is [correctly implemented][479].
- [Handle syntax errors in custom-defined visualizations][#1341]. The IDE is now
- [Handle syntax errors in custom-defined visualizations][1341]. The IDE is now
able to run properly, even if some of the custom-defined visualisations inside
a project contain syntax errors.
- [Fix issues with pasting multi-line text into single-line text fields][1348].
The first copied line will be inserted and all additional lines will be
ignored.
- [Users can opt out of anonymous data gathering.][1328] This can be done with
the `--no-data-gathering` command-line flag during the startup of the IDE.
- [You can now start the IDE service without window again.][1353] The command
Expand All @@ -66,6 +69,9 @@ you can find their release notes
[1064]: https://github.com/enso-org/ide/pull/1064
[1316]: https://github.com/enso-org/ide/pull/1316
[1318]: https://github.com/enso-org/ide/pull/1318
[1328]: https://github.com/enso-org/ide/pull/1328
[1341]: https://github.com/enso-org/ide/pull/1341
[1348]: https://github.com/enso-org/ide/pull/1348
[1353]: https://github.com/enso-org/ide/pull/1353

<br/>
Expand Down
22 changes: 21 additions & 1 deletion src/rust/ensogl/lib/text/src/component/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl Area {
eval_ sels_cut (m.buffer.frp.delete_left());

eval_ input.paste (m.paste());
eval input.paste_string ((s) m.buffer.frp.paste(m.decode_paste(s)));
eval input.paste_string((s) m.paste_string(s));


eval_ m.buffer.frp.text_change (m.redraw(true));
Expand Down Expand Up @@ -954,10 +954,30 @@ impl AreaModel {
clipboard::read_text(move |t| paste_string.emit(t));
}

/// Paste new text in the place of current selections / cursors. In case of pasting multiple
/// chunks (e.g. after copying multiple selections), the chunks will be pasted into subsequent
/// selections. In case there are more chunks than selections, end chunks will be dropped. In
/// case there is more selections than chunks, end selections will be replaced with empty
/// strings. I `self.single_line` is set to true then each chunk will be truncated to its first
/// line.
fn paste_string(&self, s: &str) {
let mut chunks = self.decode_paste(s);
if self.single_line.get() {
for f in &mut chunks {
Self::drop_all_but_first_line(f);
}
}
self.buffer.frp.paste(chunks);
}

fn decode_paste(&self, encoded:&str) -> Vec<String> {
encoded.split(RECORD_SEPARATOR).map(|s|s.into()).collect()
}

fn drop_all_but_first_line(s: &mut String) {
*s = s.lines().nth(0).unwrap_or("").to_string();
}

fn key_to_string(&self, key:&Key) -> Option<String> {
match key {
Key::Character(s) => Some(s.clone()),
Expand Down

0 comments on commit a59a3b5

Please sign in to comment.