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

Render only a certain amount of lines on live preview #200

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,20 @@
},
"fountain.general.previewTexture": {
"type": "boolean",
"default": true,
"default": false,
"description": "Noise texture on the live preview (absent from PDF)"
}
},
"fountain.renderCursor": {
"type": "boolean",
"default": true,
"description": "Render only a certain number of lines around the cursor"
},
"fountain.numLines": {
"type": "integer",
"default": 500,
"description": "Number of lines to render around the cursor"
}

}
},
{
Expand Down
50 changes: 48 additions & 2 deletions src/configloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,52 @@ export var getFountainConfig = function(docuri:vscode.Uri):FountainConfig{
synchronized_markup_and_preview: generalConfig.synchronizedMarkupAndPreview,
preview_theme: generalConfig.previewTheme,
preview_texture: generalConfig.previewTexture,
parenthetical_newline_helper: generalConfig.parentheticalNewLineHelper
parenthetical_newline_helper: generalConfig.parentheticalNewLineHelper,
numLines: generalConfig.get("numLines", 500), // new config property
}
}
}

// Render preview with cursor
function renderCursor(activateCursor: boolean, numLines: number): void {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}

if (!activateCursor) {
renderPreview();
return;
}

const cursorPos = getCursorPosition();
const startLine = Math.max(0, cursorPos.line - Math.floor(numLines / 2));
const endLine = Math.min(editor.document.lineCount - 1, startLine + numLines - 1);
const visibleRange = new vscode.Range(startLine, 0, endLine, editor.document.lineAt(endLine).text.length);
editor.revealRange(visibleRange, vscode.TextEditorRevealType.InCenter);
renderPreview();
}

// Get the cursor position
function getCursorPosition(): vscode.Position {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return new vscode.Position(0, 0);
}

return editor.selection.active;
}

// Render preview
function renderPreview(): void {
// Your code to render the preview here
}

// Activate the extension
export function activate(context: vscode.ExtensionContext) {
const config = vscode.workspace.getConfiguration('fountain');
const activateCursor = config.get<boolean>('renderCursor', true);
const numLines = config.get<number>('numLines', 500);

// Call renderCursor with the settings
renderCursor(activateCursor, numLines);
}
15 changes: 14 additions & 1 deletion src/providers/Preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,17 @@ export class FountainPreviewSerializer implements vscode.WebviewPanelSerializer
//webviewPanel.webview.postMessage({ command: 'updateTitle', content: state.title_html });
//webviewPanel.webview.postMessage({ command: 'updateScript', content: state.screenplay_html });
}
}
}
function renderCursor(activateCursor: boolean, numLines: number): void {
if (!activateCursor) {
renderPreview();
return;
}

const cursorPos = getCursorPosition();
const startLine = Math.max(0, cursorPos.line - Math.floor(numLines / 2));
const endLine = Math.min(editor.lineCount - 1, startLine + numLines - 1);
const visibleRange = new vscode.Range(startLine, 0, endLine, editor.document.lineAt(endLine).text.length);
editor.revealRange(visibleRange, vscode.TextEditorRevealType.InCenter);
renderPreview();
}