Skip to content

Commit

Permalink
Implement Separate Delays for Line Change and Inline Navigation
Browse files Browse the repository at this point in the history
This update introduces distinct delays for line changes and inline navigation. The update aims to enhance user experience by adjusting the delay based on the user's navigation behavior. When the user navigates within the same line, likely reading content character by character or word by word, longer delays are applied to minimize interference with screen reader output. Conversely, when the user changes lines, possibly skimming through the program, shorter delays are implemented to provide timely feedback. This approach ensures a balance between providing necessary accessibility signals and maintaining a smooth reading experience.
  • Loading branch information
ramoncorominas committed Feb 16, 2024
1 parent 6797048 commit 128ccb3
Showing 1 changed file with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export class SignalLineFeatureContribution
if (!position) {
return false;
}
feature.trackLineChanged(position);

return lineFeatureState.read(reader).isPresent(position);
}
);
Expand Down Expand Up @@ -202,13 +204,19 @@ interface LineFeature {
editor: ICodeEditor,
model: ITextModel
): IObservable<LineFeatureState>;
trackLineChanged(position: Position): void;
getDelay(modality: SignalModality): number;
}

interface LineFeatureState {
isPresent(position: Position): boolean;
}

type DelayType = {
line: number;
inline: number;
};

abstract class BaseLineFeature implements LineFeature {
// mandatory properties of the original LineFeature interface
abstract signal: AccessibilitySignal;
Expand All @@ -218,13 +226,33 @@ abstract class BaseLineFeature implements LineFeature {
): IObservable<LineFeatureState>;

// Holds the current delay values associated with this feature
protected _modalityDelays: Map<SignalModality, number> = new Map();
protected _modalityDelays: Map<SignalModality, DelayType> = new Map();
protected setModalityDelays(modality: SignalModality, lineDelay: number, inlineDelay: number) {
this._modalityDelays.set(modality, { line: lineDelay, inline: inlineDelay });
}

protected _previousLine: number = 0;
protected _lineChanged: boolean = false;
public trackLineChanged(position: Position) {
this._lineChanged = position.lineNumber !== this._previousLine;
this._previousLine = position.lineNumber;
}

constructor() {
// set default delays to "info" feature type (longer delays)
// TODO: Retrieve values from user-configurable settings
this.setModalityDelays(SignalModality.Sound, 300, 600);
this.setModalityDelays(SignalModality.Announcement, 600, 1500);
}

public getDelay(modality: SignalModality): number {
let minDelay = Infinity;
for (const [key, delay] of this._modalityDelays) {
if ((modality & key) !== 0 && delay < minDelay) {
minDelay = delay;
for (const [key, delayObj] of this._modalityDelays) {
if ((modality & key) !== 0) {
const delay = this._lineChanged ? delayObj.line : delayObj.inline;
if (delay < minDelay) {
minDelay = delay;
}
}
}
return minDelay === Infinity ? 0 : minDelay;
Expand All @@ -234,7 +262,6 @@ abstract class BaseLineFeature implements LineFeature {
class MarkerLineFeature extends BaseLineFeature implements LineFeature {
public readonly debounceWhileTyping = true;

private _previousLine: number = 0;
constructor(
public readonly signal: AccessibilitySignal,
private readonly severity: MarkerSeverity,
Expand All @@ -243,8 +270,8 @@ class MarkerLineFeature extends BaseLineFeature implements LineFeature {
) {
super();
// TODO: Retrieve values from user-configurable settings
this._modalityDelays.set(SignalModality.Sound, 50);
this._modalityDelays.set(SignalModality.Announcement, 500);
this.setModalityDelays(SignalModality.Sound, 0, 300);
this.setModalityDelays(SignalModality.Announcement, 300, 600);
}

getObservableState(editor: ICodeEditor, model: ITextModel): IObservable<LineFeatureState> {
Expand All @@ -254,14 +281,12 @@ class MarkerLineFeature extends BaseLineFeature implements LineFeature {
),
() => /** @description this.markerService.onMarkerChanged */({
isPresent: (position) => {
const lineChanged = position.lineNumber !== this._previousLine;
this._previousLine = position.lineNumber;
const hasMarker = this.markerService
.read({ resource: model.uri })
.some(
(m) => {
const onLine = m.severity === this.severity && m.startLineNumber <= position.lineNumber && position.lineNumber <= m.endLineNumber;
return lineChanged ? onLine : onLine && (position.lineNumber <= m.endLineNumber && m.startColumn <= position.column && m.endColumn >= position.column);
return this._lineChanged ? onLine : onLine && (position.lineNumber <= m.endLineNumber && m.startColumn <= position.column && m.endColumn >= position.column);
});
return hasMarker;
},
Expand All @@ -275,9 +300,6 @@ class FoldedAreaLineFeature extends BaseLineFeature implements LineFeature {

constructor() {
super();
// TODO: Retrieve values from user-configurable settings
this._modalityDelays.set(SignalModality.Sound, 500);
this._modalityDelays.set(SignalModality.Announcement, 1500);
}

getObservableState(editor: ICodeEditor, model: ITextModel): IObservable<LineFeatureState> {
Expand Down Expand Up @@ -309,9 +331,6 @@ class BreakpointLineFeature extends BaseLineFeature implements LineFeature {

constructor(@IDebugService private readonly debugService: IDebugService) {
super();
// TODO: Retrieve values from user-configurable settings
this._modalityDelays.set(SignalModality.Sound, 400);
this._modalityDelays.set(SignalModality.Announcement, 1000);
}

getObservableState(editor: ICodeEditor, model: ITextModel): IObservable<LineFeatureState> {
Expand Down

0 comments on commit 128ccb3

Please sign in to comment.