Another round of polishing (#101)

* Implement basic refactorings

* Simplify some match statements

* Rename `ix` to `index`

If we're not going with a single letter name,
then a full word makes more sense.

* Rename `as_hex` to `to_hex`

`as_` implies lossless reinterpretation
while the function does a conversion that loses information

* Replace `for_each` with for loops

for loops are a lot easier to read and maintain.

* factor out x and y coords in Line::render

this is arguably more ergonomic

* Remove redundant `format!(format_args!())`
This commit is contained in:
T0mstone
2021-05-04 15:08:24 +02:00
committed by Keavon Chambers
parent c9fea54ec5
commit 47458115b8
12 changed files with 65 additions and 73 deletions

View File

@@ -7,6 +7,7 @@ use wasm_bindgen::prelude::*;
fn convert_error(err: editor_core::EditorError) -> JsValue {
Error::new(&err.to_string()).into()
}
mod mouse_state {
pub(super) type MouseKeys = u8;
use editor_core::events::{self, Event, MouseState, ViewportPosition};
@@ -35,6 +36,7 @@ mod mouse_state {
}
}
}
/// Modify the currently selected tool in the document state store
#[wasm_bindgen]
pub fn select_tool(tool: String) -> Result<(), JsValue> {

View File

@@ -38,7 +38,7 @@ impl log::Log for WasmLog {
log::Level::Info => (info, "info", "color:#1b8"),
log::Level::Error => (error, "error", "color:red"),
};
let msg = &format!("{}", format_args!("%c{}\t{}", name, record.args()));
let msg = &format!("%c{}\t{}", name, record.args());
log(msg, color)
}
fn flush(&self) {}

View File

@@ -86,30 +86,30 @@ pub fn translate_append_mode(name: &str) -> Option<SelectAppendMode> {
}
pub fn translate_key(name: &str) -> events::Key {
use events::Key as K;
use events::Key::*;
match name {
"e" => K::KeyE,
"v" => K::KeyV,
"l" => K::KeyL,
"p" => K::KeyP,
"r" => K::KeyR,
"m" => K::KeyM,
"x" => K::KeyX,
"z" => K::KeyZ,
"y" => K::KeyY,
"0" => K::Key0,
"1" => K::Key1,
"2" => K::Key2,
"3" => K::Key3,
"4" => K::Key4,
"5" => K::Key5,
"6" => K::Key6,
"7" => K::Key7,
"8" => K::Key8,
"9" => K::Key9,
"Enter" => K::KeyEnter,
"Shift" => K::KeyShift,
"Alt" => K::KeyAlt,
_ => K::UnknownKey,
"e" => KeyE,
"v" => KeyV,
"l" => KeyL,
"p" => KeyP,
"r" => KeyR,
"m" => KeyM,
"x" => KeyX,
"z" => KeyZ,
"y" => KeyY,
"0" => Key0,
"1" => Key1,
"2" => Key2,
"3" => Key3,
"4" => Key4,
"5" => Key5,
"6" => Key6,
"7" => Key7,
"8" => Key8,
"9" => Key9,
"Enter" => KeyEnter,
"Shift" => KeyShift,
"Alt" => KeyAlt,
_ => UnknownKey,
}
}