mirror of https://github.com/helix-editor/helix
Add text-width to config.toml
parent
9d73a0d112
commit
404406ac6a
|
@ -57,6 +57,7 @@ on unix operating systems.
|
||||||
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` |
|
| `rulers` | List of column positions at which to display the rulers. Can be overridden by language specific `rulers` in `languages.toml` file. | `[]` |
|
||||||
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
|
| `bufferline` | Renders a line at the top of the editor displaying open buffers. Can be `always`, `never` or `multiple` (only shown if more than one buffer is in use) | `never` |
|
||||||
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
|
| `color-modes` | Whether to color the mode indicator with different colors depending on the mode itself | `false` |
|
||||||
|
| `text-width` | Set the maximum line width for text wrapping with :reflow | `80` |
|
||||||
|
|
||||||
### `[editor.statusline]` Section
|
### `[editor.statusline]` Section
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub struct LanguageConfiguration {
|
||||||
pub shebangs: Vec<String>, // interpreter(s) associated with language
|
pub shebangs: Vec<String>, // interpreter(s) associated with language
|
||||||
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
|
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
|
||||||
pub comment_token: Option<String>,
|
pub comment_token: Option<String>,
|
||||||
pub max_line_length: Option<usize>,
|
pub text_width: Option<usize>,
|
||||||
|
|
||||||
#[serde(default, skip_serializing, deserialize_with = "deserialize_lsp_config")]
|
#[serde(default, skip_serializing, deserialize_with = "deserialize_lsp_config")]
|
||||||
pub config: Option<serde_json::Value>,
|
pub config: Option<serde_json::Value>,
|
||||||
|
|
|
@ -2,6 +2,6 @@ use smartstring::{LazyCompact, SmartString};
|
||||||
|
|
||||||
/// Given a slice of text, return the text re-wrapped to fit it
|
/// Given a slice of text, return the text re-wrapped to fit it
|
||||||
/// within the given width.
|
/// within the given width.
|
||||||
pub fn reflow_hard_wrap(text: &str, max_line_len: usize) -> SmartString<LazyCompact> {
|
pub fn reflow_hard_wrap(text: &str, text_width: usize) -> SmartString<LazyCompact> {
|
||||||
textwrap::refill(text, max_line_len).into()
|
textwrap::refill(text, text_width).into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1740,30 +1740,26 @@ fn reflow(
|
||||||
}
|
}
|
||||||
|
|
||||||
let scrolloff = cx.editor.config().scrolloff;
|
let scrolloff = cx.editor.config().scrolloff;
|
||||||
|
let cfg_text_width: usize = cx.editor.config().text_width;
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
|
|
||||||
const DEFAULT_MAX_LEN: usize = 79;
|
// Find the text_width by checking the following sources in order:
|
||||||
|
|
||||||
// Find the max line length by checking the following sources in order:
|
|
||||||
// - The passed argument in `args`
|
// - The passed argument in `args`
|
||||||
// - The configured max_line_len for this language in languages.toml
|
// - The configured text-width for this language in languages.toml
|
||||||
// - The const default we set above
|
// - The configured text-width in the config.toml
|
||||||
let max_line_len: usize = args
|
let text_width: usize = args
|
||||||
.get(0)
|
.get(0)
|
||||||
.map(|num| num.parse::<usize>())
|
.map(|num| num.parse::<usize>())
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.or_else(|| {
|
.or_else(|| doc.language_config().and_then(|config| config.text_width))
|
||||||
doc.language_config()
|
.unwrap_or(cfg_text_width);
|
||||||
.and_then(|config| config.max_line_length)
|
|
||||||
})
|
|
||||||
.unwrap_or(DEFAULT_MAX_LEN);
|
|
||||||
|
|
||||||
let rope = doc.text();
|
let rope = doc.text();
|
||||||
|
|
||||||
let selection = doc.selection(view.id);
|
let selection = doc.selection(view.id);
|
||||||
let transaction = Transaction::change_by_selection(rope, selection, |range| {
|
let transaction = Transaction::change_by_selection(rope, selection, |range| {
|
||||||
let fragment = range.fragment(rope.slice(..));
|
let fragment = range.fragment(rope.slice(..));
|
||||||
let reflowed_text = helix_core::wrap::reflow_hard_wrap(&fragment, max_line_len);
|
let reflowed_text = helix_core::wrap::reflow_hard_wrap(&fragment, text_width);
|
||||||
|
|
||||||
(range.from(), range.to(), Some(reflowed_text))
|
(range.from(), range.to(), Some(reflowed_text))
|
||||||
});
|
});
|
||||||
|
|
|
@ -241,6 +241,8 @@ pub struct Config {
|
||||||
pub auto_format: bool,
|
pub auto_format: bool,
|
||||||
/// Automatic save on focus lost. Defaults to false.
|
/// Automatic save on focus lost. Defaults to false.
|
||||||
pub auto_save: bool,
|
pub auto_save: bool,
|
||||||
|
/// Set a global text_width
|
||||||
|
pub text_width: usize,
|
||||||
/// Time in milliseconds since last keypress before idle timers trigger.
|
/// Time in milliseconds since last keypress before idle timers trigger.
|
||||||
/// Used for autocompletion, set to 0 for instant. Defaults to 400ms.
|
/// Used for autocompletion, set to 0 for instant. Defaults to 400ms.
|
||||||
#[serde(
|
#[serde(
|
||||||
|
@ -764,6 +766,7 @@ impl Default for Config {
|
||||||
indent_guides: IndentGuidesConfig::default(),
|
indent_guides: IndentGuidesConfig::default(),
|
||||||
color_modes: false,
|
color_modes: false,
|
||||||
soft_wrap: SoftWrap::default(),
|
soft_wrap: SoftWrap::default(),
|
||||||
|
text_width: 80,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue