     // MARK: - Target action
     
     @objc private func tapAction(_ sender: UITapGestureRecognizer) {
+        hideMenu()
         guard let node = selectNode(at: sender.location(in: self)) else { return }
         showMenu(for: node)
     }
     
     @objc private func longPressAction(_ sender: UILongPressGestureRecognizer) {
+        hideMenu()
         guard let node = selectNode(at: sender.location(in: self)) else { return }
         showCursor(for: node)
     }
     
     @IBAction open func undoAction(_ sender: UIButton?) {
-        if !isWritingMode { isWritingMode = true }
+        if !isWritingMode {
+            hideMenu()
+            isWritingMode = true
+        }
         if let rect = manager.undo() {
             setNeedsDisplay(rect)
         }
     }
     
     @IBAction open func redoAction(_ sender: UIButton?) {
-        if !isWritingMode { isWritingMode = true }
+        if !isWritingMode {
+            hideMenu()
+            isWritingMode = true
+        }
         if let rect = manager.redo() {
             setNeedsDisplay(rect)
         }
     }
     
     @IBAction open func removeAction(_ sender: UIButton?) {
-        guard selectedNodeLayer != nil else { return }
-        
-        selectedNodeLayer!.removeFromSuperlayer()
-        candidatesView!.removeFromSuperview()
+        hideMenu()
         
         if let rect = manager.removeSelectedNode() {
             setNeedsDisplay(rect)

            ctx.fill(CGRect(origin: CGPoint.zero, size: node.frame.size))
            ctx.translateBy(x: -node.frame.origin.x, y: -node.frame.origin.y)

            if let arrStrokeInk = node.ink as? [StrokeInk] {
                ctx.setLineWidth(lineWidth)
                ctx.setLineCap(.round)
                
                for strokeInk in arrStrokeInk { ctx.addPath(strokeInk.path.cgPath) }
                
                ctx.strokePath()
            } else {
                let charInk = (node.ink as! [CharacterInk])[0]
                
                guard let image = getImage(for: charInk, strokeColor: selectionStrokeColor)?.cgImage else { return }
                ctx.draw(image, in: charInk.frame)
            }
            
            ctx.restoreGState()
            image = UIGraphicsGetImageFromCurrentImageContext()?.cgImage

    }
    
    open func replace(with character: Character) {
        hideMenu()
        
        if let rect = manager.replaceSelectedNode(with: character) {
            setNeedsDisplay(rect)
        }
    }
    
    // MARK: - MyScriptParser delegate
