Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run selected text if available instead of complete exercise code #514

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ learnr (development version)
* Added Basque language support (@mikelmadina [#489](https://github.com/rstudio/learnr/pull/489))
* Added Turkish language support (@hyigit2, @coatless [#493](https://github.com/rstudio/learnr/pull/493))
* Added option for quickly restoring a tutorial without re-evaluating the last stored exercise submission. This feature is enabled by setting the global option `tutorial.quick_restore = TRUE` or the environment variable `TUTORIAL_QUICK_RESTORE=1` (thanks @mstackhouse, [#509](https://github.com/rstudio/learnr/pull/509)).
* Clicking "Run Code" or using the keyboard shortcut (Cmd/Ctrl + Enter) now runs the selected code only, if any code is selected ([#512](https://github.com/rstudio/learnr/issues/512)).


## Bug fixes
Expand Down
9 changes: 6 additions & 3 deletions inst/lib/tutorial/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,15 +1364,18 @@ Tutorial.prototype.$initializeExerciseEvaluation = function() {
// get the label
value.label = exerciseLabel(el);

// running code or submitting an answer for checking?
value.should_check = this.should_check;

// get the code from the editor
var editor = ace.edit($(el).attr('id'));
value.code = editor.getSession().getValue();
value.code = value.should_check
? editor.getSession().getValue()
: editor.getSelectedText() || editor.getSession().getValue();
Comment on lines +1372 to +1374
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


// restore flag
value.restore = this.restore;

value.should_check = this.should_check;

// some randomness to ensure we re-execute on button clicks
value.timestamp = new Date().getTime();

Expand Down