Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl+A in TextEditor should select all text #2153

Open
2 tasks done
jgcodes2020 opened this issue Dec 1, 2023 · 2 comments · May be fixed by #2321
Open
2 tasks done

Ctrl+A in TextEditor should select all text #2153

jgcodes2020 opened this issue Dec 1, 2023 · 2 comments · May be fixed by #2321
Labels
bug Something isn't working

Comments

@jgcodes2020
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

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

What happened?

Here's an SSCCE. Try typing in the text field and pressing Ctrl + A.

use iced::{Settings, Sandbox, window};
use iced::widget::{text_editor, container};

fn main() -> iced::Result {
    App::run(Settings {
        window: window::Settings {
            size: (640, 480),
            ..Default::default()
        },
        ..Default::default()
    })?;
    
    Ok(())
}

struct App {
    content: text_editor::Content,
}

#[derive(Debug, Clone)]
enum AppMessage {
    Edit(text_editor::Action)
}


impl Sandbox for App {
    type Message = AppMessage;

    fn new() -> Self {
        Self {
            content: text_editor::Content::new()
        }
    }

    fn title(&self) -> String {
        String::from("example")
    }

    fn update(&mut self, message: Self::Message) {
        match message {
            AppMessage::Edit(action) => {
                self.content.perform(action);
            },
        }
    }

    fn view(&self) -> iced::Element<'_, Self::Message> {
        let edit_box = text_editor(&self.content).on_action(AppMessage::Edit);
        
        container(edit_box).padding(10).into()
    }
}

What is the expected behavior?

It should select all the text in the text editor.

Version

master

Operating System

Linux

Do you have any log output?

Below is log output. It doesn't seem relevant though, as it's always printed for some reason.
warning: queue 0x7fa058000ca0 destroyed while proxies still attached:
  zwp_primary_selection_offer_v1@4278190080 still attached
  wl_data_offer@4278190081 still attached
  zwp_primary_selection_device_v1@48 still attached
  zwp_primary_selection_device_manager_v1@43 still attached
  wl_data_device@47 still attached
  wl_data_device_manager@45 still attached
  wl_seat@44 still attached
  wl_registry@42 still attached
warning: queue 0x558df7ffb3b0 destroyed while proxies still attached:
  wl_buffer@56 still attached
  wl_buffer@58 still attached
  wl_shm_pool@60 still attached
  xdg_wm_base@25 still attached
  wl_output@16 still attached
  zwp_text_input_manager_v3@15 still attached
  wl_output@14 still attached
  xdg_activation_v1@13 still attached
  wl_subcompositor@12 still attached
  zwp_relative_pointer_manager_v1@11 still attached
  zwp_pointer_constraints_v1@10 still attached
  wl_seat@9 still attached
  wl_shm@8 still attached
  wp_fractional_scale_manager_v1@7 still attached
  wp_viewporter@6 still attached
  zxdg_decoration_manager_v1@5 still attached
  wl_compositor@4 still attached
  wl_registry@2 still attached
@jgcodes2020 jgcodes2020 added the bug Something isn't working label Dec 1, 2023
@jhannyj
Copy link
Contributor

jhannyj commented Jan 26, 2024

I tried implementing this myself but ran into a serious issue. Moving the cursor from the start of a file to the end of a file is seriously really slow. The bottle neck can be found in the TextEditor's layout and draw functions. I only looked into the layout function because the problem seems to lie within cosmic_text. Specifically, the TextEditor layout function calls the iced graphics text editor update function which then calls cosmic_text editor shape_as_needed function.

The problem with shape_as_needed is that it calculates and caches the layout of all the lines which haven't been cached. Of course, this is an issue because if we jump from the start of a 1000 line file to the end, we only really see the last 30 or so lines depending on the size of the editor. Yet, the layout of more than 900 unseen lines are being computed.

Also, as previously mentioned the draw function is also really slow during this process. I haven't looked into it too much, but I'm pretty sure it has to do with the internal.editor.highlight() call.

Currently a select all feature could be implemented but it'd be unusable unless there's a way to get around the unnecessary processing.

@nicoburns
Copy link
Contributor

Note: this should be Cmd+A on macOS. On macOS Ctrl+A is emacs-style "move cursor to start of line" (and Ctrl+E is "move cursor to end of line").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants