This repository was archived by the owner on Jul 22, 2025. It is now read-only.
generated from discourse/discourse-plugin-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 41
FIX: apply diffs more consistently #1367
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -24,8 +24,8 @@ export default class ModalDiffModal extends Component { | |
|
|
||
| @tracked loading = false; | ||
| @tracked finalResult = ""; | ||
| @tracked selectedText = escapeExpression(this.args.model.selectedText); | ||
| @tracked diffStreamer = new DiffStreamer(this.selectedText); | ||
| @tracked escapedSelectedText = escapeExpression(this.args.model.selectedText); | ||
| @tracked diffStreamer = new DiffStreamer(this.args.model.selectedText); | ||
| @tracked suggestion = ""; | ||
| @tracked | ||
| smoothStreamer = new SmoothStreamer( | ||
|
|
@@ -45,11 +45,16 @@ export default class ModalDiffModal extends Component { | |
|
|
||
| // Prevents flash by showing the | ||
| // original text when the diff is empty | ||
| return this.selectedText; | ||
| return this.escapedSelectedText; | ||
| } | ||
|
|
||
| get isStreaming() { | ||
| return this.diffStreamer.isStreaming || this.smoothStreamer.isStreaming; | ||
| // diffStreamer stops "streaming" when it is finished with a chunk | ||
| return ( | ||
| this.diffStreamer.isStreaming || | ||
| !this.diffStreamer.isDone || | ||
| this.smoothStreamer.isStreaming | ||
| ); | ||
| } | ||
|
|
||
| get primaryBtnLabel() { | ||
|
|
@@ -71,7 +76,7 @@ export default class ModalDiffModal extends Component { | |
| @bind | ||
| unsubscribe() { | ||
| const channel = "/discourse-ai/ai-helper/stream_composer_suggestion"; | ||
| this.messageBus.subscribe(channel, this.updateResult); | ||
| this.messageBus.unsubscribe(channel, this.updateResult); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh wow, nice catch |
||
| } | ||
|
|
||
| @action | ||
|
|
@@ -105,7 +110,7 @@ export default class ModalDiffModal extends Component { | |
| data: { | ||
| location: "composer", | ||
| mode: this.args.model.mode, | ||
| text: this.selectedText, | ||
| text: this.args.model.selectedText, | ||
| custom_prompt: this.args.model.customPromptValue, | ||
| force_default_locale: true, | ||
| client_id: this.messageBus.clientId, | ||
|
|
@@ -122,7 +127,7 @@ export default class ModalDiffModal extends Component { | |
|
|
||
| if (this.suggestion) { | ||
| this.args.model.toolbarEvent.replaceText( | ||
| this.selectedText, | ||
| this.args.model.selectedText, | ||
| this.suggestion | ||
| ); | ||
| } | ||
|
|
@@ -131,8 +136,12 @@ export default class ModalDiffModal extends Component { | |
| this.finalResult?.length > 0 | ||
| ? this.finalResult | ||
| : this.diffStreamer.suggestion; | ||
|
|
||
| if (this.args.model.showResultAsDiff && finalResult) { | ||
| this.args.model.toolbarEvent.replaceText(this.selectedText, finalResult); | ||
| this.args.model.toolbarEvent.replaceText( | ||
| this.args.model.selectedText, | ||
| finalResult | ||
| ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -647,7 +647,7 @@ | |
|
|
||
| .desktop-view & { | ||
| // a little extra space for extra narrow desktop view | ||
| @media screen and (width <= 675px) { | ||
| @media screen and (max-width: 675px) { | ||
| span { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably update this to use our |
||
| display: none; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like that when you are done you should not be streaming anymore. So setting isDone to true should also set isStreaming to false, otherwise we will plague the code with this double check.