iced icon indicating copy to clipboard operation
iced copied to clipboard

TextEditor not working properly inside of scrollable

Open nacl42 opened this issue 8 months ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues.

Is this issue related to iced?

  • [X] My hardware is compatible and my graphics drivers are up-to-date.

What happened?

I am using the new TextEditor widget from git for my project. It works just fine when I use it as it is.

However, I wanted to put it inside of a scrollable because I have several text editor widgets at the same time.

There were two bugs associated when doing this:

  1. The frame around the text editor does not appear anymore.
  2. The program crashes when I use the mouse wheel to scroll.

I have recreated the problem by modifying the editor example.

These are the modifications:

diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index 03d1e283..85ee6d0f 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -4,7 +4,7 @@ use iced::keyboard;
 use iced::theme::{self, Theme};
 use iced::widget::{
     button, column, container, horizontal_space, pick_list, row, text,
-    text_editor, tooltip,
+    text_editor, tooltip, scrollable,
 };
 use iced::{
     Alignment, Application, Command, Element, Font, Length, Settings,
@@ -19,7 +19,7 @@ use std::sync::Arc;
 pub fn main() -> iced::Result {
     Editor::run(Settings {
         fonts: vec![include_bytes!("../fonts/icons.ttf").as_slice().into()],
-        default_font: Font::MONOSPACE,
+        //default_font: Font::MONOSPACE,
         ..Settings::default()
     })
 }
@@ -190,7 +190,8 @@ impl Application for Editor {

         column![
             controls,
-            text_editor(&self.content)
+            scrollable(
+                text_editor(&self.content)
                 .on_action(Message::ActionPerformed)
                 .highlight::<Highlighter>(
                     highlighter::Settings {
@@ -204,7 +205,8 @@ impl Application for Editor {
                             .unwrap_or(String::from("rs")),
                     },
                     |highlight, _theme| highlight.to_format()
-                ),
+                )

text_editor text_editor_in_scrollable

What is the expected behavior?

The appearance of the text_editor should be independent of the surrounding widget. The text_editor should not panic.

Version

master

Operating System

Linux

Do you have any log output?

thread 'main' panicked at /home/nv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cosmic-text-0.10.0/src/buffer.rs:488:26:
attempt to add with overflow
stack backtrace:
   0:     0x55cfefa355dc - std::backtrace_rs::backtrace::libunwind::trace::he43a6a3949163f8c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55cfefa355dc - std::backtrace_rs::backtrace::trace_unsynchronized::h50db52ca99f692e7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55cfefa355dc - std::sys_common::backtrace::_print_fmt::hd37d595f2ceb2d3c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x55cfefa355dc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h678bbcf9da6d7d75
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x55cfefa62cec - core::fmt::rt::Argument::fmt::h3a159adc080a6fc9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0x55cfefa62cec - core::fmt::write::hb8eaf5a8e45a738e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0x55cfefa3180e - std::io::Write::write_fmt::h9663fe36b2ee08f9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0x55cfefa353c4 - std::sys_common::backtrace::_print::hcd4834796ee88ad2
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x55cfefa353c4 - std::sys_common::backtrace::print::h1360e9450e4f922a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x55cfefa36a73 - std::panicking::default_hook::{{closure}}::h2609fa95cd5ab1f4
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0x55cfefa3678c - std::panicking::default_hook::h6d75f5747cab6e8d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0x55cfefa36ff9 - std::panicking::rust_panic_with_hook::h57e78470c47c84de
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:707:13
  12:     0x55cfefa36eb1 - std::panicking::begin_panic_handler::{{closure}}::h3dfd2453cf356ecb
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:597:13
  13:     0x55cfefa35b06 - std::sys_common::backtrace::__rust_end_short_backtrace::hdb177d43678e4d7e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:170:18
  14:     0x55cfefa36c42 - rust_begin_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
  15:     0x55cfee396cd3 - core::panicking::panic_fmt::hd1e971d8d7c78e0e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
  16:     0x55cfee396d63 - core::panicking::panic::hd907d42d09324a32
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:117:5
  17:     0x55cfef64a27d - cosmic_text::buffer::Buffer::shape_until_scroll::h69bc5e4d6605ad58
                               at /home/nv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cosmic-text-0.10.0/src/buffer.rs:488:26
  18:     0x55cfef6398c5 - <cosmic_text::edit::editor::Editor as cosmic_text::edit::Edit>::shape_as_needed::hadc8d169517b1ed7
                               at /home/nv/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cosmic-text-0.10.0/src/edit/editor.rs:108:13
  19:     0x55cfee487f66 - <iced_graphics::text::editor::Editor as iced_core::text::editor::Editor>::update::heb5928e44af56c0e
                               at /home/nv/dev/iced/graphics/src/text/editor.rs:549:9
  20:     0x55cfee3ac721 - <iced_widget::text_editor::TextEditor<Highlighter,Message,Renderer> as iced_core::widget::Widget<Message,Renderer>>::layout::he97ca1773f0c0900
                               at /home/nv/dev/iced/widget/src/text_editor.rs:343:9
  21:     0x55cfee3e3c38 - <iced_widget::scrollable::Scrollable<Message,Renderer> as iced_core::widget::Widget<Message,Renderer>>::layout::{{closure}}::h5b4a903f51c8f8be
                               at /home/nv/dev/iced/widget/src/scrollable.rs:244:17
  22:     0x55cfee3e1a0f - iced_widget::scrollable::layout::h76ef49438ecc3223
                               at /home/nv/dev/iced/widget/src/scrollable.rs:491:19
  23:     0x55cfee3e3baf - <iced_widget::scrollable::Scrollable<Message,Renderer> as iced_core::widget::Widget<Message,Renderer>>::layout::ha07fd2f82ac72199
                               at /home/nv/dev/iced/widget/src/scrollable.rs:237:9
  24:     0x55cfee3dee47 - iced_core::layout::flex::resolve::h83aed041b07ab089
                               at /home/nv/dev/iced/core/src/layout/flex.rs:100:17
  25:     0x55cfee3bfc7c - <iced_widget::column::Column<Message,Renderer> as iced_core::widget::Widget<Message,Renderer>>::layout::h778bf5ec8ced77cb
                               at /home/nv/dev/iced/widget/src/column.rs:134:9
  26:     0x55cfee4b0930 - iced_runtime::user_interface::UserInterface<Message,Renderer>::build::hf1fe8f72ce5a4afe
                               at /home/nv/dev/iced/runtime/src/user_interface.rs:98:20
  27:     0x55cfee46ff18 - iced_winit::application::build_user_interface::hf1a0a189eade5d4c
                               at /home/nv/dev/iced/winit/src/application.rs:646:26
  28:     0x55cfee46ec34 - iced_winit::application::run_instance::{{closure}}::h1ac1114a02f54b2b
                               at /home/nv/dev/iced/winit/src/application.rs:410:56
  29:     0x55cfee471b80 - iced_winit::application::run::{{closure}}::h14f6084bdf2f65ce
                               at /home/nv/dev/iced/winit/src/application.rs:258:24
  30:     0x55cfee411401 - winit::platform_impl::platform::sticky_exit_callback::h59d56399b6fb1c51
                               at /home/nv/.cargo/git/checkouts/winit-57d3141eaf559308/c52db20/src/platform_impl/linux/mod.rs:884:9
  31:     0x55cfee3ea0a6 - winit::platform_impl::platform::x11::EventLoop<T>::run_return::single_iteration::had4bbe1643575e09
                               at /home/nv/.cargo/git/checkouts/winit-57d3141eaf559308/c52db20/src/platform_impl/linux/x11/mod.rs:358:17
  32:     0x55cfee3eace6 - winit::platform_impl::platform::x11::EventLoop<T>::run_return::h3cc614f95c4a51f7
                               at /home/nv/.cargo/git/checkouts/winit-57d3141eaf559308/c52db20/src/platform_impl/linux/x11/mod.rs:483:27
  33:     0x55cfee410756 - winit::platform_impl::platform::EventLoop<T>::run_return::h618403474403dc5f
                               at /home/nv/.cargo/git/checkouts/winit-57d3141eaf559308/c52db20/src/platform_impl/linux/mod.rs:785:56
  34:     0x55cfee39d10a - <winit::event_loop::EventLoop<T> as winit::platform::run_return::EventLoopExtRunReturn>::run_return::hc9a7b559d69aa6f4
                               at /home/nv/.cargo/git/checkouts/winit-57d3141eaf559308/c52db20/src/platform/run_return.rs:51:9
  35:     0x55cfee427b1d - iced_winit::application::platform::run::h68ab8fd4779838f7
                               at /home/nv/dev/iced/winit/src/application.rs:927:17
  36:     0x55cfee4713fd - iced_winit::application::run::h599204086eba8a53
                               at /home/nv/dev/iced/winit/src/application.rs:233:5
  37:     0x55cfee4b2d57 - iced::application::Application::run::h45ade5607f47b17a
                               at /home/nv/dev/iced/src/application.rs:208:12
  38:     0x55cfee422d36 - editor::main::h0ee0af159bb526c1
                               at /home/nv/dev/iced/examples/editor/src/main.rs:20:5
  39:     0x55cfee3f7912 - core::ops::function::FnOnce::call_once::hf0099041b5f72b25
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:250:5
  40:     0x55cfee3f1ead - std::sys_common::backtrace::__rust_begin_short_backtrace::hdb4e9809dae9d31a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:154:18
  41:     0x55cfee457f06 - std::rt::lang_start::{{closure}}::hd67af80e316c27fd
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/rt.rs:166:18
  42:     0x55cfefa2c7db - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hbcc4f8a3f5ada78c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/ops/function.rs:284:13
  43:     0x55cfefa2c7db - std::panicking::try::do_call::he5f117a9e13dadde
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:502:40
  44:     0x55cfefa2c7db - std::panicking::try::h2f3af9afce3a0443
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:466:19
  45:     0x55cfefa2c7db - std::panic::catch_unwind::h6d6c387f38ef05ea
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panic.rs:142:14
  46:     0x55cfefa2c7db - std::rt::lang_start_internal::{{closure}}::h6ca09d5905711415
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/rt.rs:148:48
  47:     0x55cfefa2c7db - std::panicking::try::do_call::ha9fd18ea06654a4b
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:502:40
  48:     0x55cfefa2c7db - std::panicking::try::hda5c2a4432362341
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:466:19
  49:     0x55cfefa2c7db - std::panic::catch_unwind::h440f731b142bc235
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panic.rs:142:14
  50:     0x55cfefa2c7db - std::rt::lang_start_internal::hc0b4e50f058f62ce
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/rt.rs:148:20
  51:     0x55cfee457eda - std::rt::lang_start::h72bec038f09b9eb6
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/rt.rs:165:17
  52:     0x55cfee4251de - main
  53:     0x7fcfe160ccd0 - <unknown>
  54:     0x7fcfe160cd8a - __libc_start_main
  55:     0x55cfee397485 - _start
  56:                0x0 - <unknown>

nacl42 avatar Nov 05 '23 18:11 nacl42

The crash is only present in the debug build.

In release build, there is no crash. However, the scroll bar behaves strange: When the scroll handle is dragged, it will not be released again. In addition, the scroll handle is very tiny and it seems as if the text editor does not give proper information about its size, i.e. the scrolling area is huge. The image above shows the tiny handle.

The border line is missing in both debug and release build.

nacl42 avatar Nov 07 '23 20:11 nacl42