如何优化梅州网站优化的WordPress附件页面?

摘要:梅州网站优化公司,wordpress附件页面,优化设计五年级下册语文答案,东莞网站制作公司联系方式前些天,写了探索Rust编写基于web_sys的WebAssembly编辑器:挑战
梅州网站优化公司,wordpress附件页面,优化设计五年级下册语文答案,东莞网站制作公司联系方式前些天#xff0c;写了探索Rust编写基于web_sys的WebAssembly编辑器#xff1a;挑战输入光标定位的实践#xff0c;经过后续的开发检验#xff0c;我发现了一个问题#xff0c;就是光标消失了。为了继续输入#xff0c;用户需要再次使用鼠标点击。现在我已经弄清楚了导致…前些天写了探索Rust编写基于web_sys的WebAssembly编辑器挑战输入光标定位的实践经过后续的开发检验我发现了一个问题就是光标消失了。为了继续输入用户需要再次使用鼠标点击。现在我已经弄清楚了导致这个问题的原因即需要找到text node来设置光标。 先上代码 let oninput use_callback(move |e: InputEvent, content1_ref1| {if let Some((selected_str, selection, parent_element)) get_selection_items() {if let Some(modified_text) parse(selected_str) {parent_element.set_inner_html(modified_text); // 更新解析后的输入 selection.remove_all_ranges().unwrap(); // 移除焦点let div content1_ref1.cast::HtmlDivElement().unwrap(); div.focus();let first_child parent_element.first_child().unwrap().first_child().unwrap(); // 这一行是关键let new_range Range::new().unwrap(); new_range.set_start(first_child, 3); // 将光标设置到第3个字符的位置new_range.collapse();selection.add_range(new_range);}}},(content1_ref.clone()),);在上面的源代码中我已经用注释标记了first_child这里是关键因为这里获取到的就是text node。为什么一定要text node呢原因在于range.set_start的第一个参数参考mozilla的文档: If the startNode is a Node of type Text, Comment, or CDataSection, then startOffset is the number of characters from the start of startNode. For other Node types, startOffset is the number of child nodes between the start of the startNode. 即如果输入的参数是text node那么上面的那个参数3就代表从开始到第3个字符的位置如果是其它类型的node就表示从开头到第3个字节点的位置。 那什么是text node呢在web_sys中它的类型引入就是web_sys::Text。可以用is_instance_of::Text()来判断 if first_child.is_instance_of::Text() { ... }在mozilla中关于Text的解释如下: The Text interface represents a text node in a DOM tree. 现在我们清楚了导致问题的原因是没有使用text node以及在set_start方法中如果node type不是text node光标将如何定位。其实关于set_start的这段解释我很早就看见了但是由于对text node无感就直接给忽略了。因此才绕了这么大的一个圈子。 好了这个小结就到这里欢迎交流可以想像后面的路会更难走。