@@ -12,6 +12,7 @@ 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" ;
@@ -23,7 +24,8 @@ export default class ModalDiffModal extends Component {
2324
2425 @tracked loading = false ;
2526 @tracked finalResult = " " ;
26- @tracked diffStreamer = new DiffStreamer (this .args .model .selectedText );
27+ @tracked selectedText = escapeExpression (this .args .model .selectedText );
28+ @tracked diffStreamer = new DiffStreamer (this .selectedText );
2729 @tracked suggestion = " " ;
2830 @tracked
2931 smoothStreamer = new SmoothStreamer (
@@ -36,6 +38,16 @@ export default class ModalDiffModal extends Component {
3638 this .suggestChanges ();
3739 }
3840
41+ get diffResult () {
42+ if (this .diffStreamer .diff ? .length > 0 ) {
43+ return this .diffStreamer .diff ;
44+ }
45+
46+ // Prevents flash by showing the
47+ // original text when the diff is empty
48+ return this .selectedText ;
49+ }
50+
3951 get isStreaming () {
4052 return this .diffStreamer .isStreaming || this .smoothStreamer .isStreaming ;
4153 }
@@ -93,7 +105,7 @@ export default class ModalDiffModal extends Component {
93105 data: {
94106 location: " composer" ,
95107 mode: this .args .model .mode ,
96- text: this .args . model . selectedText ,
108+ text: this .selectedText ,
97109 custom_prompt: this .args .model .customPromptValue ,
98110 force_default_locale: true ,
99111 },
@@ -109,7 +121,7 @@ export default class ModalDiffModal extends Component {
109121
110122 if (this .suggestion ) {
111123 this .args .model .toolbarEvent .replaceText (
112- this .args . model . selectedText ,
124+ this .selectedText ,
113125 this .suggestion
114126 );
115127 }
@@ -119,10 +131,7 @@ export default class ModalDiffModal extends Component {
119131 ? this .finalResult
120132 : this .diffStreamer .suggestion ;
121133 if (this .args .model .showResultAsDiff && finalResult) {
122- this .args .model .toolbarEvent .replaceText (
123- this .args .model .selectedText ,
124- finalResult
125- );
134+ this .args .model .toolbarEvent .replaceText (this .selectedText , finalResult);
126135 }
127136 }
128137
@@ -133,7 +142,11 @@ export default class ModalDiffModal extends Component {
133142 @ closeModal ={{@ closeModal }}
134143 >
135144 <: body >
136- <div {{didInsert this . subscribe}} {{willDestroy this . unsubscribe}} >
145+ <div
146+ {{didInsert this . subscribe}}
147+ {{willDestroy this . unsubscribe}}
148+ class =" text-preview"
149+ >
137150 {{#if this . loading }}
138151 <div class =" composer-ai-helper-modal__loading" >
139152 {{~@ model.selectedText ~}}
@@ -149,9 +162,7 @@ export default class ModalDiffModal extends Component {
149162 }}
150163 >
151164 {{~#if @ model.showResultAsDiff ~}}
152- <span class =" diff-inner" >{{htmlSafe
153- this . diffStreamer.diff
154- }} </span >
165+ <span class =" diff-inner" >{{htmlSafe this . diffResult}} </span >
155166 {{else }}
156167 {{#if this . smoothStreamer.isStreaming }}
157168 <CookText
0 commit comments