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

Wip787941 #32

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 5 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ jobs:
fail-fast: false
matrix:
include:
- php: '8.0'
moodle-branch: 'master'
- php: '8.2'
moodle-branch: 'main'
database: 'pgsql'
- php: '8.1'
moodle-branch: 'MOODLE_402_STABLE'
moodle-branch: 'MOODLE_404_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
moodle-branch: 'MOODLE_403_STABLE'
database: 'pgsql'

services:
Expand Down Expand Up @@ -92,7 +86,7 @@ jobs:

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci phpcs --max-warnings 0
run: moodle-plugin-ci phpcs # Add back --max-warnings 0 when https://github.com/moodlehq/moodle-cs/issues/155 is solved

- name: Moodle PHPDoc Checker
continue-on-error: true # This step will show errors but will not fail.
Expand Down
2 changes: 1 addition & 1 deletion amd/build/crossword_clue.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/crossword_clue.min.js.map

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions amd/src/crossword_clue.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,31 @@ export class CrosswordClue extends CrosswordQuestion {
return;
}
el.addEventListener('click', (e) => {
const {words} = this.options;
const wordNumber = e.target.closest('.wrap-clue').dataset.questionid;
const wordObj = words.find(o => o.number === parseInt(wordNumber));
// This regex matches strings that only contain space and underscores.
// That mean user has not fill any word.
const blankAnswer = /^[ _-]+$/.test(e.target.value);
const isCursorAtTheEnd = e.target.selectionEnd === e.target.value.length;
let startIndex = e.target.selectionStart;
// Check if the answer fields is clicked.
const isClicked = startIndex === e.target.selectionEnd;
// Cursor will move to the start of the clue field if the input is blank.
if (blankAnswer && isCursorAtTheEnd && isClicked) {
startIndex = 0;
}

const previousIndex = startIndex - 1;
// Check if the previous character contains hyphen or space.
const isContainSpecialCharacter = ['-', ' '].includes(e.target.value.charAt(previousIndex));
if (!isContainSpecialCharacter && isClicked) {
startIndex = (previousIndex < 0) ? 0 : previousIndex;
e.target.setSelectionRange(startIndex, startIndex);
}

// Based on the selected letter index on the answer index,
// we will find the corresponding crossword cell index.
const {words} = this.options;
const wordNumber = e.target.closest('.wrap-clue').dataset.questionid;
const wordObj = words.find(o => o.number === parseInt(wordNumber));
startIndex = this.findCellIndexFromAnswerIndex(wordObj, startIndex);
this.focusCellByStartIndex(startIndex, word);
this.focusClue();
Expand Down
5 changes: 2 additions & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Essay question type upgrade code.
* Cross word question type upgrade code.
*
* @package qtype
* @subpackage crossword
* @package qtype_crossword
* @copyright 2022 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down
Loading
Loading