Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ See [CLOUD.md](CLOUD.md) for detailed cloud documentation.
| **Ctrl+Y** | Redo |
| **Tab** | Indent (2 spaces) |
| **Shift+Tab** | Unindent |
| **Ctrl+Shift+End** | Add blank line at end of file |
| **Enter** | New line |
| **Backspace** | Delete character (joins lines at start) |

Expand Down
19 changes: 18 additions & 1 deletion src/components/TextBuffer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { highlightMarkdownLine } from '../utils/syntaxHighlight.js';

let lineIdCounter = 0;

export function appendBlankLineToEnd(existingLines) {
return [
...existingLines,
{ id: `line-${lineIdCounter++}`, text: '' },
];
}

/**
* Wrap a line of text to fit within maxWidth, breaking at word boundaries
*/
Expand Down Expand Up @@ -437,7 +444,17 @@ export default function TextBuffer({ content, onChange, isFocused = true, viewpo
}

if (key.end) {
if (key.ctrl) {
if (key.ctrl && key.shift) {
// Ctrl+Shift+End: Add new line at end of file and move cursor there
const newLines = appendBlankLineToEnd(lines);

saveToHistory(lines, cursorLine, cursorCol);
setLines(newLines);
const lastLine = newLines.length - 1;
setCursorLine(lastLine);
setCursorCol(0);
setSelection(null);
} else if (key.ctrl) {
// Ctrl+End: Go to end of file
const lastLine = lines.length - 1;
setCursorLine(lastLine);
Expand Down
19 changes: 19 additions & 0 deletions tests/components/TextBuffer.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, it, expect } from '@jest/globals';
import { appendBlankLineToEnd } from '../../src/components/TextBuffer.jsx';

describe('TextBuffer helpers', () => {
it('appendBlankLineToEnd adds a blank line without mutating original array', () => {
const originalLines = [
{ id: 'line-1', text: 'Hello' },
{ id: 'line-2', text: 'World' },
];

const result = appendBlankLineToEnd(originalLines);

expect(result).not.toBe(originalLines);
expect(result).toHaveLength(originalLines.length + 1);
expect(result.slice(0, originalLines.length)).toEqual(originalLines);
expect(result[result.length - 1].text).toBe('');
expect(result[result.length - 1].id).toMatch(/^line-/);
});
});