Skip to content

Commit 38b9049

Browse files
committed
DEV: Only show raw diff changes in preview
1 parent f041962 commit 38b9049

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

assets/javascripts/discourse/components/modal/diff-modal.gjs

+12-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class ModalDiffModal extends Component {
5656
this.messageBus.subscribe(channel, this.updateResult);
5757
}
5858

59-
compareText(oldText = "", newText = "") {
59+
compareText(oldText = "", newText = "", opts = {}) {
6060
const oldWords = oldText.trim().split(/\s+/);
6161
const newWords = newText.trim().split(/\s+/);
6262

@@ -76,7 +76,7 @@ export default class ModalDiffModal extends Component {
7676
wordHTML = newWord;
7777
}
7878

79-
if (i === newWords.length - 1) {
79+
if (i === newWords.length - 1 && opts.markLastWord) {
8080
wordHTML = `<mark class="highlight">${wordHTML}</mark>`;
8181
}
8282

@@ -103,24 +103,28 @@ export default class ModalDiffModal extends Component {
103103
}
104104

105105
if (result.done) {
106-
this.finalDiff = result.diff;
106+
// this.finalDiff = result.diff;
107107
}
108108

109109
this.lastResultText = newText;
110-
111110
this.isStreaming = !result.done;
112111
}
113112

114113
streamNextWord() {
115114
if (this.currentWordIndex === this.words.length) {
116-
this.diff = this.finalDiff;
115+
this.diff = this.compareText(
116+
this.args.model.selectedText,
117+
this.suggestion,
118+
{ markLastWord: false }
119+
);
117120
}
118121

119122
if (this.currentWordIndex < this.words.length) {
120123
this.suggestion += this.words[this.currentWordIndex] + " ";
121124
this.diff = this.compareText(
122125
this.args.model.selectedText,
123-
this.suggestion
126+
this.suggestion,
127+
{ markLastWord: true }
124128
);
125129

126130
this.currentWordIndex++;
@@ -153,8 +157,6 @@ export default class ModalDiffModal extends Component {
153157
});
154158
} catch (e) {
155159
popupAjaxError(e);
156-
} finally {
157-
this.loading = false;
158160
}
159161
}
160162

@@ -189,7 +191,8 @@ export default class ModalDiffModal extends Component {
189191
"streamable-content"
190192
}}
191193
>
192-
<CookText @rawText={{this.diff}} class="cooked" />
194+
{{!-- <CookText @rawText={{this.diff}} class="cooked" /> --}}
195+
{{htmlSafe this.diff}}
193196
{{!-- <div class="composer-ai-helper-modal__old-value">
194197
{{@model.selectedText}}
195198
{{!-- {{#if this.smoothStreamer.isStreaming}}

assets/stylesheets/modules/ai-helper/common/ai-helper.scss

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@
2121
}
2222

2323
// TODO: cleanup and scope to inline-diff class
24-
.composer-ai-helper-modal__suggestion .cooked {
24+
.composer-ai-helper-modal__suggestion.streamable-content {
2525
ins,
2626
del {
2727
text-decoration: none;
2828
}
2929

30+
ins {
31+
background-color: var(--success-low);
32+
}
33+
34+
del {
35+
background-color: var(--danger-low);
36+
}
37+
3038
mark {
3139
background-color: var(--highlight-low) !important;
3240
border-bottom: 2px solid var(--highlight-high) !important;

0 commit comments

Comments
 (0)