Added "encompass" key
This commit is contained in:
parent
17c455b73d
commit
2f2c381d71
32
main.go
32
main.go
@ -83,12 +83,17 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
|
|||||||
}, modifiers.Alt, false, false)
|
}, modifiers.Alt, false, false)
|
||||||
redraw()
|
redraw()
|
||||||
application.Draw()
|
application.Draw()
|
||||||
|
|
||||||
|
case '\\':
|
||||||
|
insertOperation('?', false, true)
|
||||||
|
redraw()
|
||||||
|
application.Draw()
|
||||||
|
|
||||||
case
|
case
|
||||||
'+', '-', '*', '/', 'p', 'P', '%', '|', '~', '&', '^', 'm',
|
'+', '-', '*', '/', 'p', 'P', '%', '|', '~', '&', '^', 'm',
|
||||||
'l', 'r':
|
'l', 'r':
|
||||||
|
|
||||||
insertOperation(rune(button), modifiers.Alt)
|
insertOperation(rune(button), modifiers.Alt, false)
|
||||||
redraw()
|
redraw()
|
||||||
application.Draw()
|
application.Draw()
|
||||||
|
|
||||||
@ -244,9 +249,10 @@ func onPress (button stone.Button, modifiers stone.Modifiers) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertOperation (symbol rune, swap bool) {
|
func insertOperation (symbol rune, swap, encompass bool) {
|
||||||
var opcode Opcode
|
var opcode Opcode
|
||||||
switch (symbol) {
|
switch (symbol) {
|
||||||
|
case '?': opcode = OpcodeUnknown
|
||||||
case '+': opcode = OpcodeAdd
|
case '+': opcode = OpcodeAdd
|
||||||
case '-': opcode = OpcodeSubtract
|
case '-': opcode = OpcodeSubtract
|
||||||
case '*': opcode = OpcodeMultiply
|
case '*': opcode = OpcodeMultiply
|
||||||
@ -263,6 +269,23 @@ func insertOperation (symbol rune, swap bool) {
|
|||||||
case 'm': opcode = OpcodeMean
|
case 'm': opcode = OpcodeMean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newExpression := Operation { opcode: opcode, floating: showFloat }
|
||||||
|
|
||||||
|
if encompass {
|
||||||
|
if selectedExpression == nil { return }
|
||||||
|
parent := selectedExpression.Parent()
|
||||||
|
|
||||||
|
newExpression.Adopt(selectedExpression)
|
||||||
|
if parent == nil {
|
||||||
|
expressionRoot = &newExpression
|
||||||
|
} else {
|
||||||
|
parent.Swap(selectedExpression, &newExpression)
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedExpression = &newExpression
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
operation, isOperation := selectedExpression.(*Operation)
|
operation, isOperation := selectedExpression.(*Operation)
|
||||||
if isOperation {
|
if isOperation {
|
||||||
if operation.opcode == OpcodeUnknown || swap {
|
if operation.opcode == OpcodeUnknown || swap {
|
||||||
@ -270,9 +293,8 @@ func insertOperation (symbol rune, swap bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newExpression := &Operation { opcode: opcode, floating: showFloat }
|
insertGeneric(&newExpression, swap, false, true)
|
||||||
insertGeneric(newExpression, swap, false, true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertNumber (value int64, swap, before bool) {
|
func insertNumber (value int64, swap, before bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user