-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from yoannchb-pro/dev
Dev
- Loading branch information
Showing
18 changed files
with
160 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
# CHANGELOG | ||
|
||
## v1.1.1 | ||
|
||
- Bugs correction | ||
- Support for Atto editor | ||
|
||
## v1.1.0 | ||
|
||
- Bugs correction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type Config from '@typing/config'; | ||
import type GPTAnswer from '@typing/gpt-answer'; | ||
|
||
/** | ||
* Hanlde atto editor | ||
* See: https://docs.moodle.org/404/en/Atto_editor#Atto_accessibility | ||
* @param config | ||
* @param inputList | ||
* @param gptAnswer | ||
* @returns | ||
*/ | ||
function handleAtto( | ||
config: Config, | ||
inputList: NodeListOf<HTMLElement>, | ||
gptAnswer: GPTAnswer | ||
): boolean { | ||
const input = inputList[0]; | ||
|
||
if (!input.classList.contains('qtype_essay_editor')) { | ||
return false; | ||
} | ||
|
||
const iframe = input.querySelector('iframe'); | ||
if (!iframe || !iframe.contentDocument || !iframe.contentDocument.body || !iframe.contentWindow) { | ||
return false; | ||
} | ||
const iframeBody = iframe.contentDocument.body; | ||
|
||
const textContainer = iframeBody.querySelector('p'); | ||
if (!textContainer) return false; | ||
|
||
if (config.typing) { | ||
let index = 0; | ||
const eventHandler = function (event: KeyboardEvent) { | ||
event.preventDefault(); | ||
|
||
if (event.key === 'Backspace' || index >= gptAnswer.response.length) { | ||
iframe.contentWindow!.removeEventListener('keydown', eventHandler); | ||
return; | ||
} | ||
|
||
// Append text one character at a time | ||
const textNode = document.createTextNode(gptAnswer.response.charAt(index++)); | ||
textContainer.appendChild(textNode); | ||
|
||
// Move the cursor after the last character | ||
const range = iframe.contentDocument!.createRange(); | ||
range.selectNodeContents(textContainer); | ||
range.collapse(false); // Collapse the range to the end point | ||
const selection = iframe.contentWindow!.getSelection(); | ||
if (selection) { | ||
selection.removeAllRanges(); | ||
selection.addRange(range); | ||
} | ||
|
||
iframe.contentWindow!.focus(); // Focus the iframe window to see cursor | ||
}; | ||
|
||
iframe.contentWindow.addEventListener('keydown', eventHandler); | ||
} else { | ||
textContainer.textContent += gptAnswer.response; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export default handleAtto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters