<commit_before>import { Injectable, SecurityContext } from '@angular/core';
import * as showdown from 'showdown';
import { DomSanitizer } from '@angular/platform-browser';
import { MarkDownElement } from 'app/entities/quiz-question';
import { ExplanationCommand, HintCommand } from 'app/markdown-editor/domainCommands';
import { AceEditorComponent } from 'ng2-ace-editor';

@Injectable({ providedIn: 'root' })
export class ArtemisMarkdown {

    /**
     * adds the passed text into the editor of the passed ace editor component at the current curser by focusing, clearing a selection,
     * moving the cursor to the end of the line, and finally inserting the given text.
     * After that the new test will be selected
     *
     * @param text the text that will be added into the editor of the passed ace editor component
     * @param aceEditorContainer holds the editor in which the text will be added at the current curser position
     */
    static addTextAtCursor(text: String, aceEditorContainer: AceEditorComponent) {
        aceEditorContainer.getEditor().focus();
        aceEditorContainer.getEditor().clearSelection();
        aceEditorContainer.getEditor().moveCursorTo(aceEditorContainer.getEditor().getCursorPosition().row, Number.POSITIVE_INFINITY);
        aceEditorContainer.getEditor().insert(text);
        const range = aceEditorContainer.getEditor().selection.getRange();
        range.setStart(range.start.row, 6);
        aceEditorContainer.getEditor().selection.setRange(range);
    }

    constructor(private sanitizer: DomSanitizer) {}

    /**
     * Parse the markdown text and apply the result to the target object's data
     *
     * The markdown text is split at HintCommand.identifier and ExplanationCommand.identifier tags.
     *  => First part is text. Everything after HintCommand.identifier is Hint, anything after ExplanationCommand.identifier is explanation
     *
     * @param markdownText {string} the markdown text to parse
     * @param targetObject {object} the object that the result will be saved in. Fields modified are 'text', 'hint' and 'explanation'.
     */
    parseTextHintExplanation(markdownText: string, targetObject: MarkDownElement) {<commit_msg>Adjust the selected text range after inserting domain commands into the new markdown editor (#225)<commit_after>import { Injectable, SecurityContext } from '@angular/core';
import * as showdown from 'showdown';
import { DomSanitizer } from '@angular/platform-browser';
import { MarkDownElement } from 'app/entities/quiz-question';
import { ExplanationCommand, HintCommand } from 'app/markdown-editor/domainCommands';
import { AceEditorComponent } from 'ng2-ace-editor';

@Injectable({ providedIn: 'root' })
export class ArtemisMarkdown {

    /**
     * adds the passed text into the editor of the passed ace editor component at the current curser by focusing, clearing a selection,
     * moving the cursor to the end of the line, and finally inserting the given text.
     * After that the new test will be selected
     *
     * @param text the text that will be added into the editor of the passed ace editor component
     * @param aceEditorContainer holds the editor in which the text will be added at the current curser position
     */
    static addTextAtCursor(text: String, aceEditorContainer: AceEditorComponent) {
        aceEditorContainer.getEditor().focus();
        aceEditorContainer.getEditor().clearSelection();
        aceEditorContainer.getEditor().moveCursorTo(aceEditorContainer.getEditor().getCursorPosition().row, Number.POSITIVE_INFINITY);
        aceEditorContainer.getEditor().insert(text);
        const range = aceEditorContainer.getEditor().selection.getRange();
        const commandIdentifier = text.split(']');
        const offsetRange = commandIdentifier[0].length + 1;
        range.setStart(range.start.row, offsetRange);
        aceEditorContainer.getEditor().selection.setRange(range);
    }
    
    constructor(private sanitizer: DomSanitizer) {}

    /**
     * Parse the markdown text and apply the result to the target object's data
     *
     * The markdown text is split at HintCommand.identifier and ExplanationCommand.identifier tags.
     *  => First part is text. Everything after HintCommand.identifier is Hint, anything after ExplanationCommand.identifier is explanation
     *
     * @param markdownText {string} the markdown text to parse
     * @param targetObject {object} the object that the result will be saved in. Fields modified are 'text', 'hint' and 'explanation'.
     */
    parseTextHintExplanation(markdownText: string, targetObject: MarkDownElement) {
{'fraction_non_alphanumeric': 0.08525793222533995, 'fraction_numerical': 0.0017267429311461256, 'mean_word_length': 4.00972972972973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '823942', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1158, 'n_words': 419}