Class: Graphlyte::Editor::Action

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#definitionObject (readonly)

Returns the value of attribute definition.



53
54
55
# File 'lib/graphlyte/editor.rb', line 53

def definition
  @definition
end

#documentObject (readonly)

Returns the value of attribute document.



53
54
55
# File 'lib/graphlyte/editor.rb', line 53

def document
  @document
end

#new_nodesObject (readonly)

Returns the value of attribute new_nodes.



53
54
55
# File 'lib/graphlyte/editor.rb', line 53

def new_nodes
  @new_nodes
end

#parentObject (readonly)

Returns the value of attribute parent.



53
54
55
# File 'lib/graphlyte/editor.rb', line 53

def parent
  @parent
end

#pathObject (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

#deleteObject



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 expand(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