Implement the Text Tool and text layer MVP (#492)

* Add text tool

* Double click with the select tool to edit text

* Fix (I think?) transitioning to select tool

* Commit and abort text editing

* Transition to a contenteditable div and autosize

* Fix right click blocking

* Cleanup hints

* Ctrl + enter leaves text edit mode

* Render indervidual bounding boxes for text

* Re-format space indents

* Reflect font size in the textarea

* Fix change tool behaviour

* Remove starting text

* Populate the cache (caused doc load bug)

* Remove console log

* Chrome display the flashing text entry cursor

* Update overlay on input

* Cleanup input.ts

* Fix bounding boxes

* Apply review feedback

* Remove manual test

* Remove svg from gitignore

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube
2022-01-30 15:10:10 +00:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent 0da8dabba9
commit a66920aa1c
33 changed files with 1152 additions and 56 deletions
+18
View File
@@ -2,6 +2,7 @@ use super::blend_mode::BlendMode;
use super::folder::Folder;
use super::simple_shape::Shape;
use super::style::ViewMode;
use super::text::Text;
use crate::intersection::Quad;
use crate::DocumentError;
use crate::LayerId;
@@ -14,6 +15,7 @@ use std::fmt::Write;
pub enum LayerDataType {
Folder(Folder),
Shape(Shape),
Text(Text),
}
impl LayerDataType {
@@ -21,6 +23,7 @@ impl LayerDataType {
match self {
LayerDataType::Shape(s) => s,
LayerDataType::Folder(f) => f,
LayerDataType::Text(t) => t,
}
}
@@ -28,6 +31,7 @@ impl LayerDataType {
match self {
LayerDataType::Shape(s) => s,
LayerDataType::Folder(f) => f,
LayerDataType::Text(t) => t,
}
}
}
@@ -158,6 +162,20 @@ impl Layer {
_ => Err(DocumentError::NotAFolder),
}
}
pub fn as_text_mut(&mut self) -> Result<&mut Text, DocumentError> {
match &mut self.data {
LayerDataType::Text(t) => Ok(t),
_ => Err(DocumentError::NotText),
}
}
pub fn as_text(&self) -> Result<&Text, DocumentError> {
match &self.data {
LayerDataType::Text(t) => Ok(t),
_ => Err(DocumentError::NotText),
}
}
}
impl Clone for Layer {