ソースを参照

LibWeb: Limit select-all actions to editable nodes when they are focused

If the user presses ctrl+a inside an <input> element, for example, we
now select that element's text only.
Timothy Flynn 11 ヶ月 前
コミット
7ae7e3eef3
1 ファイル変更11 行追加4 行削除
  1. 11 4
      Userland/Libraries/LibWeb/HTML/Navigable.cpp

+ 11 - 4
Userland/Libraries/LibWeb/HTML/Navigable.cpp

@@ -2147,13 +2147,20 @@ void Navigable::select_all()
     auto document = active_document();
     if (!document)
         return;
-    auto* body = document->body();
-    if (!body)
-        return;
+
     auto selection = document->get_selection();
     if (!selection)
         return;
-    (void)selection->select_all_children(*document->body());
+
+    if (auto position = document->cursor_position(); position && position->node()->is_editable()) {
+        auto& node = *position->node();
+        auto node_length = node.length();
+
+        (void)selection->set_base_and_extent(node, 0, node, node_length);
+        document->set_cursor_position(DOM::Position::create(document->realm(), node, node_length));
+    } else if (auto* body = document->body()) {
+        (void)selection->select_all_children(*body);
+    }
 }
 
 void Navigable::paste(String const& text)