diff --git a/src/bookmark.rs b/src/bookmark.rs index 663c279..75a0893 100644 --- a/src/bookmark.rs +++ b/src/bookmark.rs @@ -155,9 +155,6 @@ impl Bookmarks { pub struct BookmarkSlice([Bookmark]); impl BookmarkSlice { - pub const EMPTY: &'static BookmarkSlice = unsafe { core::mem::transmute::<&[Bookmark], &Self>(&[]) }; - pub const EMPTY_MUT: &'static mut BookmarkSlice = unsafe { core::mem::transmute::<&mut [Bookmark], &mut Self>(&mut []) }; - #[inline] pub fn increment(&mut self, value: usize, true_value: usize) { for bookmark in &mut self.0 { @@ -262,13 +259,13 @@ impl> Index for BookmarkSlice { fn index(&self, index: R) -> &Self::Output { match (index.start_bound().map(|&x| Bookmark::new(x, 0)), index.end_bound().map(|&x| Bookmark::new(x, 0))) { (Bound::Unbounded, Bound::Unbounded) => self, - (Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY } else { slice!(self.0[..=end]) } }, + (Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice!([]) } else { slice!(self.0[..=end]) } }, (Bound::Unbounded, Bound::Excluded(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); slice!(self.0[..end]) }, (Bound::Included(ref start), Bound::Unbounded) => { let start = self.binary_search(start).unwrap_or_else(identity); slice!(self.0[start..]) }, - (Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY } else { slice!(self.0[start..=end]) } }, + (Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice!([]) } else { slice!(self.0[start..=end]) } }, (Bound::Included(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); slice!(self.0[start..end]) }, (Bound::Excluded(ref start), Bound::Unbounded) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); slice!(self.0[start..]) }, - (Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY } else { slice!(self.0[start..=end]) } }, + (Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice!([]) } else { slice!(self.0[start..=end]) } }, (Bound::Excluded(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); slice!(self.0[start..end]) }, } } @@ -278,13 +275,13 @@ impl> IndexMut for BookmarkSlice { fn index_mut(&mut self, index: R) -> &mut Self::Output { match (index.start_bound().map(|&x| Bookmark::new(x, 0)), index.end_bound().map(|&x| Bookmark::new(x, 0))) { (Bound::Unbounded, Bound::Unbounded) => self, - (Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY_MUT } else { slice_mut!(self.0[..=end]) } }, + (Bound::Unbounded, Bound::Included(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice_mut!([]) } else { slice_mut!(self.0[..=end]) } }, (Bound::Unbounded, Bound::Excluded(ref end)) => { let end = self.binary_search(end).unwrap_or_else(identity); slice_mut!(self.0[..end]) }, (Bound::Included(ref start), Bound::Unbounded) => { let start = self.binary_search(start).unwrap_or_else(identity); slice_mut!(self.0[start..]) }, - (Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY_MUT } else { slice_mut!(self.0[start..=end]) } }, + (Bound::Included(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice_mut!([]) } else { slice_mut!(self.0[start..=end]) } }, (Bound::Included(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).unwrap_or_else(identity); let end = self.binary_search(end).unwrap_or_else(identity); slice_mut!(self.0[start..end]) }, (Bound::Excluded(ref start), Bound::Unbounded) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); slice_mut!(self.0[start..]) }, - (Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { BookmarkSlice::EMPTY_MUT } else { slice_mut!(self.0[start..=end]) } }, + (Bound::Excluded(ref start), Bound::Included(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); if end >= self.len() { slice_mut!([]) } else { slice_mut!(self.0[start..=end]) } }, (Bound::Excluded(ref start), Bound::Excluded(ref end)) => { let start = self.binary_search(start).map_or_else(identity, |x| x + 1); let end = self.binary_search(end).unwrap_or_else(identity); slice_mut!(self.0[start..end]) }, } } diff --git a/src/elements/compound.rs b/src/elements/compound.rs index 36d7adc..70a5026 100644 --- a/src/elements/compound.rs +++ b/src/elements/compound.rs @@ -1,6 +1,5 @@ use std::alloc::{alloc, Layout}; use std::cmp::Ordering; -use std::convert::identity; use std::fmt::{Display, Formatter, Write}; use std::hash::Hasher; use std::intrinsics::likely; diff --git a/src/workbench.rs b/src/workbench.rs index a23b701..ae6c7a3 100644 --- a/src/workbench.rs +++ b/src/workbench.rs @@ -2281,7 +2281,7 @@ impl Workbench { LIGHT_STRIPE_UV + (1, 1) }; builder.draw_texture_region_z( - (0, n * 16 + HEADER_SIZE + (n > 0) as usize), + (0, n * 16 + HEADER_SIZE - (n == 0) as usize), BASE_Z, uv, (builder.window_width(), 16 + (n == 0) as usize), @@ -2324,7 +2324,7 @@ impl Workbench { let mut ctx = RenderContext::new(selected_y, selected_key, selected_value, selecting_key, ghost, left_margin, (self.mouse_x, self.mouse_y), tab.freehand_mode); if self.mouse_y >= HEADER_SIZE && self.action_wheel.is_none() { builder.draw_texture_region_z( - (0, (self.mouse_y & !15) + 1), + (0, (self.mouse_y & !15)), BASE_Z, HOVERED_STRIPE_UV, (builder.window_width(), 16), diff --git a/src/workbench_action.rs b/src/workbench_action.rs index 1073e95..b90431f 100644 --- a/src/workbench_action.rs +++ b/src/workbench_action.rs @@ -1,4 +1,3 @@ -use std::convert::identity; use std::mem::MaybeUninit; use compact_str::{CompactString, ToCompactString}; use std::path::PathBuf; diff --git a/web/index.html b/web/index.html index 3072be8..9f341d3 100644 --- a/web/index.html +++ b/web/index.html @@ -52,7 +52,7 @@ import init, { open_file } from "./nbtworkbench.js?version=2"; await init(); - const canvas = document.getElementById("canvas")[0]; + const canvas = document.getElementById("canvas"); dialog.onchange = event => { const file = event.target.files.item(0); @@ -61,7 +61,6 @@ }) }; - canvas.addEventListener("pointerdown", openDialog); canvas.addEventListener("pointerup", openDialog); canvas.addEventListener("keydown", openDialog);