aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelippe da Motta Raposo <raposo.felippe@gmail.com>2018-06-08 16:32:21 -0700
committerChristian Duerr <chrisduerr@users.noreply.github.com>2018-06-08 23:32:21 +0000
commit6cbae83f174fa6d114ea66b1f8dd6185950ca835 (patch)
tree178a869a7fce12cc34eecd684a17d6340c9cd589
parent66acf1e03da4d0206e3368bf58953b071887ccb2 (diff)
downloadalacritty-6cbae83f174fa6d114ea66b1f8dd6185950ca835.tar.gz
alacritty-6cbae83f174fa6d114ea66b1f8dd6185950ca835.zip
Reduce Increase-/DecreaseFontSize step to 0.5
Until now the Increase-/DecreaseFontSize keybinds hand a step size of 1.0. Since the font size however is multiplied by two to allow more granular font size control, this lead to the bindings skipping one font size (incrementing/decrementing by +-2). To fix this the step size of the Increase-/DecreaseFontSize bindings has been reduced to the minimum step size that exists with the current font configuration (0.5). This should allow users to increment and decrement the font size by a single point instead of two. This also adds a few tests to make sure the methods for increasing/decreasing/resetting font size work properly.
-rw-r--r--src/event.rs2
-rw-r--r--src/input.rs10
-rw-r--r--src/term/mod.rs78
3 files changed, 81 insertions, 9 deletions
diff --git a/src/event.rs b/src/event.rs
index 4ae25860..f592da5c 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -106,7 +106,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize)
}
- fn change_font_size(&mut self, delta: i8) {
+ fn change_font_size(&mut self, delta: f32) {
self.terminal.change_font_size(delta);
}
diff --git a/src/input.rs b/src/input.rs
index 2d603783..7afd359d 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -34,6 +34,8 @@ use term::SizeInfo;
use term::mode::TermMode;
use util::fmt::Red;
+pub const FONT_SIZE_STEP: f32 = 0.5;
+
/// Processes input from glutin.
///
/// An escape sequence may be emitted in case specific keys or key combinations
@@ -62,7 +64,7 @@ pub trait ActionContext {
fn received_count(&mut self) -> &mut usize;
fn suppress_chars(&mut self) -> &mut bool;
fn last_modifiers(&mut self) -> &mut ModifiersState;
- fn change_font_size(&mut self, delta: i8);
+ fn change_font_size(&mut self, delta: f32);
fn reset_font_size(&mut self);
}
@@ -227,10 +229,10 @@ impl Action {
::std::process::exit(0);
},
Action::IncreaseFontSize => {
- ctx.change_font_size(1);
+ ctx.change_font_size(FONT_SIZE_STEP);
},
Action::DecreaseFontSize => {
- ctx.change_font_size(-1);
+ ctx.change_font_size(-FONT_SIZE_STEP);
}
Action::ResetFontSize => {
ctx.reset_font_size();
@@ -698,7 +700,7 @@ mod tests {
fn last_modifiers(&mut self) -> &mut ModifiersState {
&mut self.last_modifiers
}
- fn change_font_size(&mut self, _delta: i8) {
+ fn change_font_size(&mut self, _delta: f32) {
}
fn reset_font_size(&mut self) {
}
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 4f56e7fc..27cc9312 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -30,6 +30,7 @@ use selection::{self, Span, Selection};
use config::{Config, VisualBellAnimation};
use {MouseCursor, Rgb};
use copypasta::{Clipboard, Load, Store};
+use input::FONT_SIZE_STEP;
pub mod cell;
pub mod color;
@@ -841,10 +842,10 @@ impl Term {
}
}
- pub fn change_font_size(&mut self, delta: i8) {
- // Saturating addition with minimum font size 1
- let new_size = self.font_size + Size::new(f32::from(delta));
- self.font_size = max(new_size, Size::new(1.));
+ pub fn change_font_size(&mut self, delta: f32) {
+ // Saturating addition with minimum font size FONT_SIZE_STEP
+ let new_size = self.font_size + Size::new(delta);
+ self.font_size = max(new_size, Size::new(FONT_SIZE_STEP));
self.dirty = true;
}
@@ -1947,6 +1948,9 @@ mod tests {
use ansi::{Handler, CharsetIndex, StandardCharset};
use selection::Selection;
use std::mem;
+ use input::FONT_SIZE_STEP;
+ use font::Size;
+ use config::Config;
#[test]
fn semantic_selection_works() {
@@ -2052,6 +2056,72 @@ mod tests {
assert_eq!(term.grid()[&cursor].c, '▒');
}
+
+ fn change_font_size_works(font_size: f32) {
+ let size = SizeInfo {
+ width: 21.0,
+ height: 51.0,
+ cell_width: 3.0,
+ cell_height: 3.0,
+ padding_x: 0.0,
+ padding_y: 0.0,
+ };
+ let config: Config = Default::default();
+ let mut term: Term = Term::new(&config, size);
+ term.change_font_size(font_size);
+
+ let expected_font_size: Size = config.font().size() + Size::new(font_size);
+ assert_eq!(term.font_size, expected_font_size);
+ }
+
+ #[test]
+ fn increase_font_size_works() {
+ change_font_size_works(10.0);
+ }
+
+ #[test]
+ fn decrease_font_size_works() {
+ change_font_size_works(-10.0);
+ }
+
+ #[test]
+ fn prevent_font_below_threshold_works() {
+ let size = SizeInfo {
+ width: 21.0,
+ height: 51.0,
+ cell_width: 3.0,
+ cell_height: 3.0,
+ padding_x: 0.0,
+ padding_y: 0.0,
+ };
+ let config: Config = Default::default();
+ let mut term: Term = Term::new(&config, size);
+
+ term.change_font_size(-100.0);
+
+ let expected_font_size: Size = Size::new(FONT_SIZE_STEP);
+ assert_eq!(term.font_size, expected_font_size);
+ }
+
+ #[test]
+ fn reset_font_size_works() {
+ let size = SizeInfo {
+ width: 21.0,
+ height: 51.0,
+ cell_width: 3.0,
+ cell_height: 3.0,
+ padding_x: 0.0,
+ padding_y: 0.0,
+ };
+ let config: Config = Default::default();
+ let mut term: Term = Term::new(&config, size);
+
+ term.change_font_size(10.0);
+ term.reset_font_size();
+
+ let expected_font_size: Size = config.font().size();
+ assert_eq!(term.font_size, expected_font_size);
+ }
}
#[cfg(all(test, feature = "bench"))]