Skip to content

Instantly share code, notes, and snippets.

@koca
Last active March 20, 2022 18:56
Show Gist options
  • Save koca/82dcf2bdd1844961b74b4ec4a1eec4db to your computer and use it in GitHub Desktop.
Save koca/82dcf2bdd1844961b74b4ec4a1eec4db to your computer and use it in GitHub Desktop.
repo:vue-prism-editor repro:newline

Weird line numbers issue

if i copy the text below and paste it to editor, it works because the text ** contains** the new line char \n at the end of the string

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n\nThis is a second line of text.

but if i copy the text below and paste it to editor, line numbers height won't match for some reason the text doesn't contain any new line char \n at the end of the string

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
This is a second line of text.

image

weird fix:

const defaultLineHeight = ($lineNumbersWrapper.querySelector('.vpe-lw') as HTMLDivElement).offsetHeight;
if (lineNumber === 0 && codeLines[codeLines.length - 1] === '') {
  // if (lineNumber === 0 && currentLineSize > defaultLineHeight * 2 && this.lineNumbersCount) {
  currentLineSize -= defaultLineHeight;
}          
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment