Share and unify limit for intra line diffs

Closes #13838
This commit is contained in:
Markus Olsson 2022-02-07 16:17:29 +01:00
parent df3b265232
commit b36b67d5b9
3 changed files with 10 additions and 6 deletions

View file

@ -387,3 +387,9 @@ export function getLargestLineNumber(hunks: DiffHunk[]): number {
export function getNumberOfDigits(val: number): number {
return (Math.log(val) * Math.LOG10E + 1) | 0
}
/**
* The longest line for which we'd try to calculate a line diff, this matches
* GitHub.com's behavior.
**/
export const MaxIntraLineDiffStringLength = 1024

View file

@ -45,6 +45,7 @@ import {
DiffColumn,
getLineWidthFromDigitCount,
getNumberOfDigits,
MaxIntraLineDiffStringLength,
} from './diff-helpers'
import { showContextualMenu } from '../main-process-proxy'
import { getTokens } from './diff-syntax-mode'
@ -59,7 +60,6 @@ import { IMenuItem } from '../../lib/menu-item'
import { HiddenBidiCharsWarning } from './hidden-bidi-chars-warning'
const DefaultRowHeight = 20
const MaxLineLengthToCalculateDiff = 240
export interface ISelectionPoint {
readonly column: DiffColumn
@ -1164,8 +1164,8 @@ function getModifiedRows(
const deletedLine = deletedLines[i]
if (
addedLine.line.content.length < MaxLineLengthToCalculateDiff &&
deletedLine.line.content.length < MaxLineLengthToCalculateDiff
addedLine.line.content.length < MaxIntraLineDiffStringLength &&
deletedLine.line.content.length < MaxIntraLineDiffStringLength
) {
const { before, after } = getDiffTokens(
deletedLine.line.content,

View file

@ -46,6 +46,7 @@ import {
canSelect,
getLineWidthFromDigitCount,
getNumberOfDigits,
MaxIntraLineDiffStringLength,
} from './diff-helpers'
import {
expandTextDiffHunk,
@ -58,9 +59,6 @@ import { WhitespaceHintPopover } from './whitespace-hint-popover'
import { PopoverCaretPosition } from '../lib/popover'
import { HiddenBidiCharsWarning } from './hidden-bidi-chars-warning'
/** The longest line for which we'd try to calculate a line diff. */
const MaxIntraLineDiffStringLength = 4096
// This is a custom version of the no-newline octicon that's exactly as
// tall as it needs to be (8px) which helps with aligning it on the line.
export const narrowNoNewlineSymbol = {