@@ -12,18 +12,21 @@ import concatClass from "discourse/helpers/concat-class";
1212import { ajax } from " discourse/lib/ajax" ;
1313import { popupAjaxError } from " discourse/lib/ajax-error" ;
1414import { bind } from " discourse/lib/decorators" ;
15+ import { escapeExpression } from " discourse/lib/utilities" ;
1516import { i18n } from " discourse-i18n" ;
1617import DiffStreamer from " ../../lib/diff-streamer" ;
1718import SmoothStreamer from " ../../lib/smooth-streamer" ;
1819import AiIndicatorWave from " ../ai-indicator-wave" ;
1920
2021export default class ModalDiffModal extends Component {
2122 @service currentUser;
23+ @service siteSettings;
2224 @service messageBus;
2325
2426 @tracked loading = false ;
2527 @tracked finalResult = " " ;
26- @tracked diffStreamer = new DiffStreamer (this .args .model .selectedText );
28+ @tracked selectedText = escapeExpression (this .args .model .selectedText );
29+ @tracked diffStreamer = new DiffStreamer (this .selectedText );
2730 @tracked suggestion = " " ;
2831 @tracked
2932 smoothStreamer = new SmoothStreamer (
@@ -36,6 +39,16 @@ export default class ModalDiffModal extends Component {
3639 this .suggestChanges ();
3740 }
3841
42+ get diffResult () {
43+ if (this .diffStreamer .diff ? .length > 0 ) {
44+ return this .diffStreamer .diff ;
45+ }
46+
47+ // Prevents flash by showing the
48+ // original text when the diff is empty
49+ return this .selectedText ;
50+ }
51+
3952 get isStreaming () {
4053 return this .diffStreamer .isStreaming || this .smoothStreamer .isStreaming ;
4154 }
@@ -93,7 +106,7 @@ export default class ModalDiffModal extends Component {
93106 data: {
94107 location: " composer" ,
95108 mode: this .args .model .mode ,
96- text: this .args . model . selectedText ,
109+ text: this .selectedText ,
97110 custom_prompt: this .args .model .customPromptValue ,
98111 force_default_locale: true ,
99112 },
@@ -109,7 +122,7 @@ export default class ModalDiffModal extends Component {
109122
110123 if (this .suggestion ) {
111124 this .args .model .toolbarEvent .replaceText (
112- this .args . model . selectedText ,
125+ this .selectedText ,
113126 this .suggestion
114127 );
115128 }
@@ -119,21 +132,23 @@ export default class ModalDiffModal extends Component {
119132 ? this .finalResult
120133 : this .diffStreamer .suggestion ;
121134 if (this .args .model .showResultAsDiff && finalResult) {
122- this .args .model .toolbarEvent .replaceText (
123- this .args .model .selectedText ,
124- finalResult
125- );
135+ this .args .model .toolbarEvent .replaceText (this .selectedText , finalResult);
126136 }
127137 }
128138
129139 <template >
140+ {{log this . prefersRichEditor}}
130141 <DModal
131142 class =" composer-ai-helper-modal"
132143 @ title ={{i18n " discourse_ai.ai_helper.context_menu.changes" }}
133144 @ closeModal ={{@ closeModal }}
134145 >
135146 <: body >
136- <div {{didInsert this . subscribe}} {{willDestroy this . unsubscribe}} >
147+ <div
148+ {{didInsert this . subscribe}}
149+ {{willDestroy this . unsubscribe}}
150+ class =" text-preview"
151+ >
137152 {{#if this . loading }}
138153 <div class =" composer-ai-helper-modal__loading" >
139154 {{~@ model.selectedText ~}}
@@ -149,9 +164,7 @@ export default class ModalDiffModal extends Component {
149164 }}
150165 >
151166 {{~#if @ model.showResultAsDiff ~}}
152- <span class =" diff-inner" >{{htmlSafe
153- this . diffStreamer.diff
154- }} </span >
167+ <span class =" diff-inner" >{{htmlSafe this . diffResult}} </span >
155168 {{else }}
156169 {{#if this . smoothStreamer.isStreaming }}
157170 <CookText
0 commit comments