Skip to content

Commit 4629576

Browse files
committed
working code, needs to be cleaned
1 parent 89db3e4 commit 4629576

File tree

4 files changed

+65
-15
lines changed

4 files changed

+65
-15
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorActions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CTX_INTERACTIVE_EDITOR_FOCUSED, CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUE
1414
import { localize } from 'vs/nls';
1515
import { IAction2Options, MenuRegistry } from 'vs/platform/actions/common/actions';
1616
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
17-
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
17+
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1818
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1919
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
2020
import { IQuickInputService, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
@@ -565,6 +565,8 @@ export class ExpandMessageAction extends AbstractInteractiveEditorAction {
565565
});
566566
}
567567
override runInteractiveEditorCommand(_accessor: ServicesAccessor, ctrl: InteractiveEditorController, _editor: ICodeEditor, ..._args: any[]): void {
568+
console.log('running the expand message action');
569+
console.log('CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE : ', CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE.getValue(_accessor.get(IContextKeyService)));
568570
ctrl.updateExpansionState(true);
569571
}
570572
}
@@ -585,6 +587,8 @@ export class ContractMessageAction extends AbstractInteractiveEditorAction {
585587
});
586588
}
587589
override runInteractiveEditorCommand(_accessor: ServicesAccessor, ctrl: InteractiveEditorController, _editor: ICodeEditor, ..._args: any[]): void {
590+
console.log('running the contract message action');
591+
console.log('CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE : ', CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE.getValue(_accessor.get(IContextKeyService)));
588592
ctrl.updateExpansionState(false);
589593
}
590594
}

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
2929
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
3030
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
3131
import { ILogService } from 'vs/platform/log/common/log';
32-
import { EditResponse, EmptyResponse, ErrorResponse, IInteractiveEditorSessionService, MarkdownResponse, Session, SessionExchange } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
32+
import { EditResponse, EmptyResponse, ErrorResponse, ExpansionState, IInteractiveEditorSessionService, MarkdownResponse, Session, SessionExchange } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
3333
import { EditModeStrategy, LivePreviewStrategy, LiveStrategy, PreviewStrategy } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorStrategies';
3434
import { InteractiveEditorZoneWidget } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget';
3535
import { CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST, CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK, IInteractiveEditorRequest, IInteractiveEditorResponse, INTERACTIVE_EDITOR_ID, EditMode, InteractiveEditorResponseFeedbackKind, CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE, InteractiveEditorResponseType, CTX_INTERACTIVE_EDITOR_DID_EDIT, CTX_INTERACTIVE_EDITOR_HAS_STASHED_SESSION } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
@@ -246,6 +246,7 @@ export class InteractiveEditorController implements IEditorContribution {
246246
}
247247

248248
this._activeSession = session;
249+
this._activeSession.newlySelected = true;
249250
return State.INIT_UI;
250251
}
251252

@@ -555,7 +556,12 @@ export class InteractiveEditorController implements IEditorContribution {
555556
this._zone.widget.updateStatus('');
556557
this._zone.widget.updateMarkdownMessage(renderedMarkdown.element);
557558
this._zone.widget.updateToolbar(true);
558-
this._zone.widget.updateMarkdownMessageExpansionState(this._activeSession.lastExpansionState);
559+
console.log('inside of SHOW_RESPONSE');
560+
console.log('this._activeSession.lastExpansionState', this._activeSession.lastExpansionState);
561+
const state = this._activeSession.newlySelected ? (this._activeSession.lastExpansionState ?? this._zone.widget.cropState()) : this._zone.widget.cropState();
562+
this._activeSession.newlySelected = false;
563+
this._activeSession.lastExpansionState = state;
564+
this._zone.widget.updateMarkdownMessageExpansionState(state);
559565

560566
} else if (response instanceof EditResponse) {
561567
// edit response -> complex...
@@ -664,9 +670,12 @@ export class InteractiveEditorController implements IEditorContribution {
664670
}
665671

666672
updateExpansionState(expand: boolean) {
673+
console.log('inside of update expansion state, expand : ', expand);
667674
if (this._activeSession) {
668-
this._zone.widget.updateMarkdownMessageExpansionState(expand);
669-
this._activeSession.lastExpansionState = expand;
675+
const state = expand ? ExpansionState.EXPANDED : ExpansionState.CROPPED;
676+
console.log('state : ', state);
677+
this._zone.widget.updateMarkdownMessageExpansionState(state);
678+
this._activeSession.lastExpansionState = state;
670679
}
671680
}
672681

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,17 @@ type TelemetryDataClassification = {
5555
editMode: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'What edit mode was choosen: live, livePreview, preview' };
5656
};
5757

58+
export enum ExpansionState {
59+
EXPANDED = 'expanded',
60+
CROPPED = 'cropped',
61+
NOT_CROPPED = 'not_cropped'
62+
}
63+
5864
export class Session {
5965

66+
private _newlySelected: boolean = false;
6067
private _lastInput: string | undefined;
61-
private _lastExpansionState: boolean | undefined;
68+
private _lastExpansionState: ExpansionState | undefined;
6269
private _lastTextModelChanges: LineRangeMapping[] | undefined;
6370
private _lastSnapshot: ITextSnapshot | undefined;
6471
private readonly _exchange: SessionExchange[] = [];
@@ -84,6 +91,14 @@ export class Session {
8491
};
8592
}
8693

94+
get newlySelected() {
95+
return this._newlySelected;
96+
}
97+
98+
set newlySelected(value: boolean) {
99+
this._newlySelected = value;
100+
}
101+
87102
addInput(input: string): void {
88103
this._lastInput = input;
89104
}
@@ -92,11 +107,11 @@ export class Session {
92107
return this._lastInput;
93108
}
94109

95-
get lastExpansionState() {
96-
return this._lastExpansionState ?? false;
110+
get lastExpansionState(): ExpansionState | undefined {
111+
return this._lastExpansionState;
97112
}
98113

99-
set lastExpansionState(state: boolean) {
114+
set lastExpansionState(state: ExpansionState) {
100115
this._lastExpansionState = state;
101116
}
102117

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
5050
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
5151
import { assertType } from 'vs/base/common/types';
5252
import { renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels';
53+
import { ExpansionState } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorSession';
5354

5455
const defaultAriaLabel = localize('aria-label', "Interactive Editor Input");
5556

@@ -356,6 +357,8 @@ export class InteractiveEditorWidget {
356357
this._store.dispose();
357358
this._ctxInputEmpty.reset();
358359
this._ctxMessageCropState.reset();
360+
console.log('inside of dispose');
361+
console.log('this._ctxMessageCropState.get() : ', this._ctxMessageCropState.get());
359362
}
360363

361364
get domNode(): HTMLElement {
@@ -428,19 +431,34 @@ export class InteractiveEditorWidget {
428431
this._onDidChangeHeight.fire();
429432
}
430433

434+
cropState() {
435+
if (this._elements.message.scrollHeight > this._elements.message.clientHeight) {
436+
return ExpansionState.CROPPED;
437+
} else {
438+
return ExpansionState.NOT_CROPPED;
439+
}
440+
}
441+
431442
updateMarkdownMessage(message: Node | undefined) {
443+
console.log('inside of update markdown message');
432444
this._elements.markdownMessage.classList.toggle('hidden', !message);
433445
if (!message) {
434446
this._ctxMessageCropState.reset();
447+
console.log('inside of case when message is undefined');
448+
console.log('this._ctxMessageCropState.get() : ', this._ctxMessageCropState.get());
435449
reset(this._elements.message);
436-
437450
} else {
451+
// reset the css to what it was before
452+
this._elements.message.style.webkitLineClamp = '3';
438453
reset(this._elements.message, message);
454+
console.log('message overflowing : ', this._elements.message.scrollHeight > this._elements.message.clientHeight);
439455
if (this._elements.message.scrollHeight > this._elements.message.clientHeight) {
440-
this._ctxMessageCropState.set('cropped');
456+
this._ctxMessageCropState.set(ExpansionState.CROPPED);
441457
} else {
442-
this._ctxMessageCropState.set('not_cropped');
458+
this._ctxMessageCropState.set(ExpansionState.NOT_CROPPED);
443459
}
460+
console.log('inside of the case when the message is defined');
461+
console.log('this._ctxMessageCropState.get() : ', this._ctxMessageCropState.get());
444462
}
445463
this._onDidChangeHeight.fire();
446464
}
@@ -489,9 +507,13 @@ export class InteractiveEditorWidget {
489507
this._inputEditor.focus();
490508
}
491509

492-
updateMarkdownMessageExpansionState(expand: boolean) {
493-
this._ctxMessageCropState.set(expand ? 'expanded' : 'cropped');
494-
this._elements.message.style.webkitLineClamp = expand ? '10' : '3';
510+
updateMarkdownMessageExpansionState(expansionState: ExpansionState) {
511+
console.log('inside of update markdown message expansion state');
512+
console.log('expansionState : ', expansionState);
513+
this._ctxMessageCropState.set(expansionState);
514+
console.log('this._ctxMessageCropState.get() : ', this._ctxMessageCropState.get());
515+
this._elements.message.style.webkitLineClamp = expansionState === ExpansionState.NOT_CROPPED ? 'none' : (expansionState === ExpansionState.EXPANDED ? '10' : '3');
516+
console.log('this._elements.message.style.webkitLineClamp : ', this._elements.message.style.webkitLineClamp);
495517
this._onDidChangeHeight.fire();
496518
}
497519

0 commit comments

Comments
 (0)