                 goal  = new Goal @core.editor, index, pos.start, pos.end - 2
                 @goals.push goal
 
-    giveAction: (index, content) ->
+    giveAction: (index, content) -> @protectCursor =>
         log 'Text Buffer', "handling give-action #{content}"
         goal = @findGoal index
         if content

            if goals.length is 1
                resolve goals[0]
            else
                warn 'Text Buffer', 'out of goal'
                @core.panel.outputInfo 'For this command, please place the cursor in a goal'
                reject()

    warnCurrentGoalIfEmpty: (goal, warning) =>
        content = goal.getContent()

        if positions.length isnt 0
            @core.editor.setCursorBufferPosition previousGoal

    give: -> @getCurrentGoalOrWarn().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to give'
        @core.executable.give goal

    goalType: -> @getCurrentGoalOrWarn().then (goal) =>
        @core.executable.goalType goal

    context: -> @getCurrentGoalOrWarn().then (goal) =>
        @core.executable.context goal

    goalTypeAndContext: -> @getCurrentGoalOrWarn().then (goal) =>
        @core.executable.goalTypeAndContext goal

    goalTypeAndInferredType: -> @getCurrentGoalOrWarn().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to infer'
        @core.executable.goalTypeAndInferredType goal

    refine: -> @getCurrentGoalOrWarn().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to refine'
        @core.executable.refine goal

    case: -> @getCurrentGoalOrWarn().then (goal) =>
        @warnCurrentGoalIfEmpty goal, 'Please type in the expression to make case'
        @core.executable.case goal

    auto: -> @getCurrentGoalOrWarn().then (goal) =>
        @core.executable.auto goal


