From 9effe71b7d2133f18545d182cef384ea3fd1c0ff Mon Sep 17 00:00:00 2001
From: Ivan Tham <pickfire@riseup.net>
Date: Wed, 30 Jun 2021 00:17:16 +0800
Subject: [PATCH] Apply suggestions from blaz for infobox

---
 Cargo.lock                         | 2 --
 helix-term/src/ui/info.rs          | 6 +-----
 helix-tui/Cargo.toml               | 1 -
 helix-tui/src/backend/test.rs      | 2 +-
 helix-tui/src/buffer.rs            | 2 +-
 helix-tui/src/text.rs              | 2 +-
 helix-tui/src/widgets/paragraph.rs | 2 +-
 helix-tui/src/widgets/reflow.rs    | 2 +-
 helix-tui/src/widgets/table.rs     | 2 +-
 helix-view/Cargo.toml              | 1 -
 helix-view/src/info.rs             | 2 +-
 helix-view/src/input.rs            | 5 +++--
 12 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 59eb894e..2cd202f3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -396,7 +396,6 @@ dependencies = [
  "helix-view",
  "serde",
  "unicode-segmentation",
- "unicode-width",
 ]
 
 [[package]]
@@ -419,7 +418,6 @@ dependencies = [
  "slotmap",
  "tokio",
  "toml",
- "unicode-width",
  "url",
  "which",
 ]
diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs
index 085a2d9b..c5709356 100644
--- a/helix-term/src/ui/info.rs
+++ b/helix-term/src/ui/info.rs
@@ -11,11 +11,7 @@ impl Component for Info {
         let (w, h) = (*width + 2, *height + 2);
         // -2 to subtract command line + statusline. a bit of a hack, because of splits.
         let area = Rect::new(viewport.width - w, viewport.height - h - 2, w, h);
-        let margin = Margin {
-            vertical: 1,
-            horizontal: 1,
-        };
-        let Rect { x, y, .. } = area.inner(&margin);
+        let Rect { x, y, .. } = block.inner(area);
         for (y, line) in (y..).zip(self.text.lines()) {
             surface.set_string(x, y, line, Style::default());
         }
diff --git a/helix-tui/Cargo.toml b/helix-tui/Cargo.toml
index dde2eafe..7f98144c 100644
--- a/helix-tui/Cargo.toml
+++ b/helix-tui/Cargo.toml
@@ -19,7 +19,6 @@ default = ["crossterm"]
 bitflags = "1.0"
 cassowary = "0.3"
 unicode-segmentation = "1.2"
-unicode-width = "0.1"
 crossterm = { version = "0.20", optional = true }
 serde = { version = "1", "optional" = true, features = ["derive"]}
 helix-view = { version = "0.3", path = "../helix-view", features = ["term"] }
diff --git a/helix-tui/src/backend/test.rs b/helix-tui/src/backend/test.rs
index a03bcd8e..3f56b49c 100644
--- a/helix-tui/src/backend/test.rs
+++ b/helix-tui/src/backend/test.rs
@@ -2,9 +2,9 @@ use crate::{
     backend::Backend,
     buffer::{Buffer, Cell},
 };
+use helix_core::unicode::width::UnicodeWidthStr;
 use helix_view::graphics::{CursorKind, Rect};
 use std::{fmt::Write, io};
-use unicode_width::UnicodeWidthStr;
 
 /// A backend used for the integration tests.
 #[derive(Debug)]
diff --git a/helix-tui/src/buffer.rs b/helix-tui/src/buffer.rs
index 3a7ad144..377e3e39 100644
--- a/helix-tui/src/buffer.rs
+++ b/helix-tui/src/buffer.rs
@@ -1,7 +1,7 @@
 use crate::text::{Span, Spans};
+use helix_core::unicode::width::UnicodeWidthStr;
 use std::cmp::min;
 use unicode_segmentation::UnicodeSegmentation;
-use unicode_width::UnicodeWidthStr;
 
 use helix_view::graphics::{Color, Modifier, Rect, Style};
 
diff --git a/helix-tui/src/text.rs b/helix-tui/src/text.rs
index 4af6b09d..b8e52479 100644
--- a/helix-tui/src/text.rs
+++ b/helix-tui/src/text.rs
@@ -47,10 +47,10 @@
 //! ]);
 //! ```
 use helix_core::line_ending::str_is_line_ending;
+use helix_core::unicode::width::UnicodeWidthStr;
 use helix_view::graphics::Style;
 use std::borrow::Cow;
 use unicode_segmentation::UnicodeSegmentation;
-use unicode_width::UnicodeWidthStr;
 
 /// A grapheme associated to a style.
 #[derive(Debug, Clone, PartialEq)]
diff --git a/helix-tui/src/widgets/paragraph.rs b/helix-tui/src/widgets/paragraph.rs
index bdfb5b9a..fee35d25 100644
--- a/helix-tui/src/widgets/paragraph.rs
+++ b/helix-tui/src/widgets/paragraph.rs
@@ -7,9 +7,9 @@ use crate::{
         Block, Widget,
     },
 };
+use helix_core::unicode::width::UnicodeWidthStr;
 use helix_view::graphics::{Rect, Style};
 use std::iter;
-use unicode_width::UnicodeWidthStr;
 
 fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) -> u16 {
     match alignment {
diff --git a/helix-tui/src/widgets/reflow.rs b/helix-tui/src/widgets/reflow.rs
index ae561a4f..21847783 100644
--- a/helix-tui/src/widgets/reflow.rs
+++ b/helix-tui/src/widgets/reflow.rs
@@ -1,7 +1,7 @@
 use crate::text::StyledGrapheme;
 use helix_core::line_ending::str_is_line_ending;
+use helix_core::unicode::width::UnicodeWidthStr;
 use unicode_segmentation::UnicodeSegmentation;
-use unicode_width::UnicodeWidthStr;
 
 const NBSP: &str = "\u{00a0}";
 
diff --git a/helix-tui/src/widgets/table.rs b/helix-tui/src/widgets/table.rs
index ee5147b7..1ee4286a 100644
--- a/helix-tui/src/widgets/table.rs
+++ b/helix-tui/src/widgets/table.rs
@@ -9,9 +9,9 @@ use cassowary::{
     WeightedRelation::*,
     {Expression, Solver},
 };
+use helix_core::unicode::width::UnicodeWidthStr;
 use helix_view::graphics::{Rect, Style};
 use std::collections::HashMap;
-use unicode_width::UnicodeWidthStr;
 
 /// A [`Cell`] contains the [`Text`] to be displayed in a [`Row`] of a [`Table`].
 ///
diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml
index b6816d71..cb2032de 100644
--- a/helix-view/Cargo.toml
+++ b/helix-view/Cargo.toml
@@ -31,7 +31,6 @@ slotmap = "1"
 
 encoding_rs = "0.8"
 chardetng = "0.1"
-unicode-width = "0.1"
 
 serde = { version = "1.0", features = ["derive"] }
 toml = "0.5"
diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs
index eef8d3a1..0eaab783 100644
--- a/helix-view/src/info.rs
+++ b/helix-view/src/info.rs
@@ -1,6 +1,6 @@
 use crate::input::KeyEvent;
+use helix_core::unicode::width::UnicodeWidthStr;
 use std::fmt::Write;
-use unicode_width::UnicodeWidthStr;
 
 #[derive(Debug)]
 /// Info box used in editor. Rendering logic will be in other crate.
diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs
index 6e8292e9..2847bb69 100644
--- a/helix-view/src/input.rs
+++ b/helix-view/src/input.rs
@@ -1,5 +1,6 @@
 //! Input event handling, currently backed by crossterm.
 use anyhow::{anyhow, Error};
+use helix_core::unicode::width::UnicodeWidthStr;
 use serde::de::{self, Deserialize, Deserializer};
 use std::fmt;
 
@@ -90,9 +91,9 @@ impl fmt::Display for KeyEvent {
     }
 }
 
-impl unicode_width::UnicodeWidthStr for KeyEvent {
+impl UnicodeWidthStr for KeyEvent {
     fn width(&self) -> usize {
-        use unicode_width::UnicodeWidthChar;
+        use helix_core::unicode::width::UnicodeWidthChar;
         let mut width = match self.code {
             KeyCode::Backspace => keys::BACKSPACE.len(),
             KeyCode::Enter => keys::ENTER.len(),