Share tab width definitions.

This commit is contained in:
Blaž Hrastnik 2020-10-14 12:01:41 +09:00
parent 0b74d423d0
commit d64f4beede
5 changed files with 6 additions and 9 deletions

View file

@ -4,7 +4,7 @@ use crate::{
Rope, RopeSlice, State, Rope, RopeSlice, State,
}; };
const TAB_WIDTH: usize = 4; pub const TAB_WIDTH: usize = 4;
fn indent_level_for_line(line: RopeSlice) -> usize { fn indent_level_for_line(line: RopeSlice) -> usize {
let mut len = 0; let mut len = 0;

View file

@ -1,7 +1,7 @@
#![allow(unused)] #![allow(unused)]
pub mod graphemes; pub mod graphemes;
mod history; mod history;
mod indent; pub mod indent;
pub mod macros; pub mod macros;
mod position; mod position;
pub mod register; pub mod register;

View file

@ -1,5 +1,5 @@
use clap::ArgMatches as Args; use clap::ArgMatches as Args;
use helix_core::{state::Mode, syntax::HighlightEvent, Range, State}; use helix_core::{indent::TAB_WIDTH, state::Mode, syntax::HighlightEvent, Range, State};
use helix_view::{commands, keymap, View}; use helix_view::{commands, keymap, View};
use std::{ use std::{
@ -24,8 +24,6 @@ use crossterm::{
use tui::{backend::CrosstermBackend, buffer::Buffer as Surface, layout::Rect, style::Style}; use tui::{backend::CrosstermBackend, buffer::Buffer as Surface, layout::Rect, style::Style};
const TAB_WIDTH: usize = 4;
type Terminal = tui::Terminal<CrosstermBackend<std::io::Stdout>>; type Terminal = tui::Terminal<CrosstermBackend<std::io::Stdout>>;
static EX: smol::Executor = smol::Executor::new(); static EX: smol::Executor = smol::Executor::new();

View file

@ -1,5 +1,6 @@
use helix_core::{ use helix_core::{
graphemes, graphemes,
indent::TAB_WIDTH,
regex::Regex, regex::Regex,
register, selection, register, selection,
state::{Direction, Granularity, Mode, State}, state::{Direction, Granularity, Mode, State},
@ -541,8 +542,6 @@ pub fn paste(view: &mut View, _count: usize) {
} }
} }
const TAB_WIDTH: usize = 4;
fn get_lines(view: &View) -> Vec<usize> { fn get_lines(view: &View) -> Vec<usize> {
let mut lines = Vec::new(); let mut lines = Vec::new();

View file

@ -5,6 +5,7 @@ use std::{borrow::Cow, path::PathBuf};
use crate::theme::Theme; use crate::theme::Theme;
use helix_core::{ use helix_core::{
graphemes::{grapheme_width, RopeGraphemes}, graphemes::{grapheme_width, RopeGraphemes},
indent::TAB_WIDTH,
History, Position, RopeSlice, State, History, Position, RopeSlice, State,
}; };
use tui::layout::Rect; use tui::layout::Rect;
@ -78,8 +79,7 @@ impl View {
for grapheme in RopeGraphemes::new(&line_slice) { for grapheme in RopeGraphemes::new(&line_slice) {
if grapheme == "\t" { if grapheme == "\t" {
// TODO: this should be const TAB_WIDTH col += TAB_WIDTH;
col += 4;
} else { } else {
let grapheme = Cow::from(grapheme); let grapheme = Cow::from(grapheme);
col += grapheme_width(&grapheme); col += grapheme_width(&grapheme);