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)
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
case '\\':
|
||||
insertOperation('?', false, true)
|
||||
redraw()
|
||||
application.Draw()
|
||||
|
||||
case
|
||||
'+', '-', '*', '/', 'p', 'P', '%', '|', '~', '&', '^', 'm',
|
||||
'l', 'r':
|
||||
|
||||
insertOperation(rune(button), modifiers.Alt)
|
||||
insertOperation(rune(button), modifiers.Alt, false)
|
||||
redraw()
|
||||
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
|
||||
switch (symbol) {
|
||||
case '?': opcode = OpcodeUnknown
|
||||
case '+': opcode = OpcodeAdd
|
||||
case '-': opcode = OpcodeSubtract
|
||||
case '*': opcode = OpcodeMultiply
|
||||
@ -263,6 +269,23 @@ func insertOperation (symbol rune, swap bool) {
|
||||
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)
|
||||
if isOperation {
|
||||
if operation.opcode == OpcodeUnknown || swap {
|
||||
@ -270,9 +293,8 @@ func insertOperation (symbol rune, swap bool) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
newExpression := &Operation { opcode: opcode, floating: showFloat }
|
||||
insertGeneric(newExpression, swap, false, true)
|
||||
|
||||
insertGeneric(&newExpression, swap, false, true)
|
||||
}
|
||||
|
||||
func insertNumber (value int64, swap, before bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user