Skip to content

Commit

Permalink
🐛 Fixed no scroll on pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Mar 26, 2024
1 parent a7e0d09 commit 1f78ba7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "omega"
version = "0.1.9"
version = "0.1.10"
repository = "https://github.com/nwrenger/omega"
documentation = "https://github.com/nwrenger/omega"
readme = "README.md"
Expand Down
9 changes: 8 additions & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ pub fn copy(text_area: &mut TextArea) -> Result<()> {
}

/// Pasts the current clipboard
pub fn paste(text_area: &mut TextArea) -> Result<()> {
pub fn paste(s: &mut Cursive, text_area: &mut TextArea) -> Result<()> {
let content = text_area.get_content().to_string();
let cursor_pos = text_area.cursor();

Expand All @@ -333,6 +333,13 @@ pub fn paste(text_area: &mut TextArea) -> Result<()> {
let inserted_line = split.0.to_string() + text.as_str() + split.1;
lines[current_line] = inserted_line.as_str();

s.call_on_all_named(
"editor_scroll",
|view: &mut ScrollView<NamedView<TextArea>>| {
view.scroll_to_bottom();
},
);

let new_content: String = lines.join("\n");
text_area.set_content(new_content);

Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ fn main() {
.with_name("editor")
.scrollable()
.scroll_strategy(ScrollStrategy::StickToBottom)
.with_name("editor_scroll")
.full_screen();

let events = OnEventView::new(text_area)
Expand All @@ -96,7 +97,7 @@ fn main() {
})
.on_pre_event(Event::CtrlChar('v'), move |s| {
if let Some(mut text_area) = s.find_name::<TextArea>("editor") {
events::paste(&mut text_area).handle(s);
events::paste(s, &mut text_area).handle(s);
}
})
.on_pre_event(Event::CtrlChar('x'), move |s| {
Expand Down

0 comments on commit 1f78ba7

Please sign in to comment.