Class: Graphlyte::Editor::Action
- Inherits:
-
Object
- Object
- Graphlyte::Editor::Action
- Defined in:
- lib/graphlyte/editor.rb
Overview
The value passed to the handler blocks, in addition to the syntax node. Users can call methods on this object to edit the document in-place, as well as read information about the context of this node.
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#new_nodes ⇒ Object
readonly
Returns the value of attribute new_nodes.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #closest(node_type) ⇒ Object
- #delete ⇒ Object
- #expand(new_nodes) ⇒ Object
-
#initialize(old_node, path, parent, document) ⇒ Action
constructor
A new instance of Action.
- #insert_after(node) ⇒ Object
- #insert_before(node) ⇒ Object
- #replace(replacement) ⇒ Object
Constructor Details
#initialize(old_node, path, parent, document) ⇒ Action
Returns a new instance of Action.
55 56 57 58 59 60 61 |
# File 'lib/graphlyte/editor.rb', line 55 def initialize(old_node, path, parent, document) @new_nodes = [old_node] @definition = path.first @path = path.dup.freeze @parent = parent @document = document end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
53 54 55 |
# File 'lib/graphlyte/editor.rb', line 53 def definition @definition end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
53 54 55 |
# File 'lib/graphlyte/editor.rb', line 53 def document @document end |
#new_nodes ⇒ Object (readonly)
Returns the value of attribute new_nodes.
53 54 55 |
# File 'lib/graphlyte/editor.rb', line 53 def new_nodes @new_nodes end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
53 54 55 |
# File 'lib/graphlyte/editor.rb', line 53 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
53 54 55 |
# File 'lib/graphlyte/editor.rb', line 53 def path @path end |
Instance Method Details
#closest(node_type) ⇒ Object
83 84 85 |
# File 'lib/graphlyte/editor.rb', line 83 def closest(node_type) @path.reverse.find { _1.is_a?(node_type) } end |
#delete ⇒ Object
75 76 77 |
# File 'lib/graphlyte/editor.rb', line 75 def delete @new_nodes = [] end |
#expand(new_nodes) ⇒ Object
79 80 81 |
# File 'lib/graphlyte/editor.rb', line 79 def (new_nodes) @new_nodes = new_nodes end |
#insert_after(node) ⇒ Object
71 72 73 |
# File 'lib/graphlyte/editor.rb', line 71 def insert_after(node) @new_nodes.push(node) end |
#insert_before(node) ⇒ Object
67 68 69 |
# File 'lib/graphlyte/editor.rb', line 67 def insert_before(node) @new_nodes = [node] + @new_nodes end |
#replace(replacement) ⇒ Object
63 64 65 |
# File 'lib/graphlyte/editor.rb', line 63 def replace(replacement) @new_nodes = [replacement] end |