Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
aliscie committed Mar 23, 2023
1 parent 7173899 commit 04da785
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions editor/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,38 @@ use shared::{
schema::{EditorChange, EditorElement, EditorElementCreate, ElementTree},
};
use uuid::Uuid;
use web_sys::{window, HtmlElement, Range};
use web_sys::{window, HtmlElement, Range, Element};
use yew::prelude::*;
use yewdux::prelude::*;

use crate::{plugins::DropDownItem, render::render};
use wasm_bindgen::JsCast;
use crate::plugins::get_caret_position;

pub fn on_slash_input(
event: DropDownItem,
// id: Id, // TODO get id of current element
range: Option<Range>,
element_tree: &ElementTree,
) -> Option<(Id, Vec<EditorChange>)> {
// if no focused element is found we are selecting the root element as focused
let current_element = window()?
.document()?
.active_element()
.and_then(|f| f.id().parse::<Uuid>().ok())
.map(Id::from)
.or(element_tree.elements.root)?;
// let current_element :HtmlElement = window()?.document()?.get_element_by_id(&id.to_string())?.dyn_into().unwrap(); // TODO this is the right way to get elements
let current_element: HtmlElement = window()?.document()?.active_element().unwrap().dyn_into::<HtmlElement>().unwrap(); // TODO this is very wrong.

let id = Id::new();
let mut changes: Vec<EditorChange> = Vec::new();

// TODO
// let caret_position = get_caret_position();
// let text = current_element.inner_text().clone();
// log!(&text);
// let (before, after) = text.split_at(caret_position as usize);
// log!(&before);
// log!(&after);

let current_element = Some(current_element).and_then(|f| f.id().parse::<Uuid>().ok())
.map(Id::from)
.or(element_tree.elements.root)?;

match event.text.as_str() {
"table" => {
// TODO we should hav ea generic way to create elements without using event.text.as_str()
Expand Down

0 comments on commit 04da785

Please sign in to comment.