Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jurredr/context description truncate #259

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added some breathing room for max width in context truncation
  • Loading branch information
Jurredr committed Mar 4, 2025
commit dc3a988dafc2caaff2664555fa8184a35a33dca9
Original file line number Diff line number Diff line change
@@ -12,22 +12,16 @@ export interface PromptInputQuickPickItemProps {
export class PromptInputQuickPickItem {
render: ExtendedHTMLElement;
private readonly props: PromptInputQuickPickItemProps;
private readonly descriptionText: ExtendedHTMLElement;
private readonly description: ExtendedHTMLElement;

constructor (props: PromptInputQuickPickItemProps) {
this.props = props;

this.descriptionText = DomBuilder.getInstance().build({
type: 'span',
classNames: [ 'mynah-chat-command-selector-command-description-text' ],
children: [ this.props.quickPickItem.description ?? '' ]
});
this.description =
DomBuilder.getInstance().build({
type: 'div',
classNames: [ 'mynah-chat-command-selector-command-description' ],
children: [ this.descriptionText ]
children: [ this.props.quickPickItem.description ?? '' ]
});

this.render = DomBuilder.getInstance().build({
@@ -115,12 +109,12 @@ export class PromptInputQuickPickItem {
const textWidth = measureElement.offsetWidth;

// Get the max width from the container
const maxWidth = this.description.offsetWidth;
const maxWidth = this.description.offsetWidth - 10;

// If the text fits, update with the original
if (textWidth <= maxWidth) {
document.body.removeChild(measureElement);
this.descriptionText.innerText = text;
this.description.innerText = text;
return;
}

@@ -143,6 +137,6 @@ export class PromptInputQuickPickItem {
document.body.removeChild(measureElement);

// Update the truncated text
this.descriptionText.innerText = text.slice(0, right) + ellipsis + text.slice(-right);
this.description.innerText = text.slice(0, right) + ellipsis + text.slice(-right);
};
}