Skip to content

Add new line support for multi-line input box (follow up PR) #1309

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

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7fcc94c
Add input multi-line support
WizardOhio24 Feb 8, 2021
a7d5008
Change commit key to alt c and newline to enter
WizardOhio24 Apr 16, 2021
e9f0b4d
commit via ctrl+o
Apr 17, 2021
18cbe48
Fix build use EventState
WizardOhio24 Apr 29, 2021
b1d19ce
Fix build
WizardOhio24 Apr 29, 2021
e764905
Add scrolling behaviour
WizardOhio24 May 23, 2021
ce8f315
Add scrollbar
WizardOhio24 May 23, 2021
bc664b5
Fix clippy errors
WizardOhio24 May 23, 2021
7a4cddf
Try to fix scrolling
WizardOhio24 May 25, 2021
5b8d7f2
Fix scrolling behaviour on incriment and decrement cursor
WizardOhio24 May 25, 2021
46b027a
Fix scrollbar scrolling
WizardOhio24 May 25, 2021
5628139
Fix up and down arrow scrolling
WizardOhio24 May 25, 2021
8b0526f
Fix clippy and remove unused variable
WizardOhio24 May 25, 2021
b552477
Remove unessessary comments
WizardOhio24 May 25, 2021
13bc8fb
Fix intersperse clippy error
WizardOhio24 May 25, 2021
e7a307f
Textbox resize to number of lines
WizardOhio24 May 25, 2021
96b6f21
Show scrollbar only if text area larger than frame
WizardOhio24 May 25, 2021
2e5ed68
Scroll up when backspace over newline char
WizardOhio24 May 25, 2021
c55fdc5
Remove else if input event consumed
WizardOhio24 May 25, 2021
9c681ee
Make command for newline only show on multiline textboxes
WizardOhio24 May 25, 2021
0410e3a
Add some comments and seperation between single and multiline
WizardOhio24 May 25, 2021
94da93e
Fix build
WizardOhio24 May 25, 2021
2dbfaa7
Fix clippy error
WizardOhio24 May 25, 2021
0f851d7
Change ends in nl to add a span
WizardOhio24 May 25, 2021
d7cc3fa
Fix moving down a line
WizardOhio24 May 25, 2021
83563a1
Some fixes
WizardOhio24 May 27, 2021
8147b5f
fixed bugs in multi line pr
guzzit Sep 1, 2022
4795b43
resolved conflicts
guzzit Sep 4, 2022
1c179b7
resolved conflicts
guzzit Sep 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
commit via ctrl+o
fix command stack
add to changelog
  • Loading branch information
Stephan Dilly authored and guzzit committed Sep 4, 2022
commit e9f0b4db207d7de0d4a3ff05c0ce2bb5cc6e1f12
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

<<<<<<< HEAD
**submodules view**

![submodules](assets/submodules.gif)
Expand Down Expand Up @@ -161,6 +162,10 @@ The way this works got changed and simplified ([See docs](https://github.com/ext
- visualize progress during async syntax highlighting ([#889](https://github.com/extrawurst/gitui/issues/889))
- added support for markdown emoji's in commits [[@andrewpollack](https://github.com/andrewpollack)] ([#768](https://github.com/extrawurst/gitui/issues/768))
- added scrollbar to revlog [[@ashvin021](https://github.com/ashvin021)] ([#868](https://github.com/extrawurst/gitui/issues/868))
=======
### Changed
- `enter` adds *newline* to commit msg (*commit* via `ctrl+o` now) [[@WizardOhio24](https://github.com/WizardOhio24)] ([#509](https://github.com/extrawurst/gitui/issues/509))
>>>>>>> commit via ctrl+o

### Fixed
- fix build when system level libgit2 version was used ([#883](https://github.com/extrawurst/gitui/issues/883))
Expand Down
81 changes: 81 additions & 0 deletions src/components/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum Mode {
Revert,
}

<<<<<<< HEAD
pub struct CommitComponent {
repo: RepoPathRef,
input: TextInputComponent,
Expand All @@ -51,6 +52,86 @@ pub struct CommitComponent {
git_branch_name: cached::BranchName,
commit_template: Option<String>,
theme: SharedTheme,
=======
impl Component for CommitComponent {
fn commands(
&self,
out: &mut Vec<CommandInfo>,
force_all: bool,
) -> CommandBlocking {
self.input.commands(out, force_all);

if self.is_visible() || force_all {
out.push(CommandInfo::new(
strings::commands::commit(&self.key_config),
self.can_commit(),
true,
));

out.push(CommandInfo::new(
strings::commands::commit_amend(&self.key_config),
self.can_amend(),
true,
));

out.push(CommandInfo::new(
strings::commands::commit_open_editor(
&self.key_config,
),
true,
true,
));
}

visibility_blocking(self)
}

fn event(&mut self, ev: Event) -> Result<bool> {
if self.is_visible() {
if let Event::Key(e) = ev {
if e == self.key_config.commit && self.can_commit() {
self.commit()?;
} else if e == self.key_config.commit_amend
&& self.can_amend()
{
self.amend()?;
} else if e == self.key_config.open_commit_editor {
self.queue.borrow_mut().push_back(
InternalEvent::OpenExternalEditor(None),
);
self.hide();
} else if self.input.event(ev)? {
return Ok(true);
}
// stop key event propagation
return Ok(true);
}
}

Ok(false)
}

fn is_visible(&self) -> bool {
self.input.is_visible()
}

fn hide(&mut self) {
self.input.hide()
}

fn show(&mut self) -> Result<()> {
if self.amend.is_some() {
self.input.clear();
}
self.amend = None;

self.input
.set_title(strings::commit_title(&self.key_config));
self.input.show()?;

Ok(())
}
>>>>>>> commit via ctrl+o
}

const FIRST_LINE_LIMIT: usize = 50;
Expand Down
95 changes: 95 additions & 0 deletions src/components/textinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ impl DrawableComponent for TextInputComponent {
}

impl Component for TextInputComponent {
<<<<<<< HEAD
fn commands(
&self,
out: &mut Vec<CommandInfo>,
Expand Down Expand Up @@ -678,6 +679,100 @@ impl Component for TextInputComponent {

Ok(())
}
=======
fn commands(
&self,
out: &mut Vec<CommandInfo>,
_force_all: bool,
) -> CommandBlocking {
out.push(
CommandInfo::new(
strings::commands::close_popup(&self.key_config),
true,
self.visible,
)
.order(1),
);

out.push(CommandInfo::new(
strings::commands::commit_new_line(&self.key_config),
true,
self.visible,
));

visibility_blocking(self)
}

fn event(&mut self, ev: Event) -> Result<bool> {
if self.visible {
if let Event::Key(e) = ev {
if e == self.key_config.exit_popup {
self.hide();
return Ok(true);
} else if e == self.key_config.enter
&& self.input_type == InputType::Multiline
{
self.msg.insert(self.cursor_position, '\n');
self.incr_cursor();
return Ok(true);
}

let is_ctrl =
e.modifiers.contains(KeyModifiers::CONTROL);

match e.code {
KeyCode::Char(c) if !is_ctrl => {
self.msg.insert(self.cursor_position, c);
self.incr_cursor();
return Ok(true);
}
KeyCode::Delete => {
if self.cursor_position < self.msg.len() {
self.msg.remove(self.cursor_position);
}
return Ok(true);
}
KeyCode::Backspace => {
self.backspace();
return Ok(true);
}
KeyCode::Left => {
self.decr_cursor();
return Ok(true);
}
KeyCode::Right => {
self.incr_cursor();
return Ok(true);
}
KeyCode::Home => {
self.cursor_position = 0;
return Ok(true);
}
KeyCode::End => {
self.cursor_position = self.msg.len();
return Ok(true);
}
_ => (),
};
}
}
Ok(false)
}

fn is_visible(&self) -> bool {
self.visible
}

fn hide(&mut self) {
self.visible = false
}

fn show(&mut self) -> Result<()> {
self.visible = true;

Ok(())
}
>>>>>>> commit via ctrl+o
}

#[cfg(test)]
Expand Down
Loading