Skip to content

Commit

Permalink
✨ tries to guess DevTools/inspector width and set options.wrap to i…
Browse files Browse the repository at this point in the history
…t when `options.wrap` is `auto`
  • Loading branch information
astoilkov committed Mar 15, 2024
1 parent b4326b2 commit b3156be
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/utils/guessAvailableLength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ export default function guessAvailableLength(): number {
// taken by DevTools for displaying the filename where the console.log() was called
const DEV_TOOLS_EXTRA_RIGHT_SPACING = 200;
const guessedAvailableWidth =
window.outerWidth -
guessDevToolsWidth() -
DEV_TOOLS_CONSOLE_X_PADDING * 2 -
DEV_TOOLS_EXTRA_RIGHT_SPACING;
return Math.round(guessedAvailableWidth / CHAR_WIDTH);
}

function guessDevToolsWidth(): number {
const widthDiff = window.outerWidth - window.innerWidth;
const heightDiff = window.outerHeight - window.innerHeight;
if (heightDiff > widthDiff && heightDiff >= 100) {
// DevTools horizontal layout
return window.innerWidth;
} else if (widthDiff > heightDiff && widthDiff >= 250) {
// DevTools vertical layout
return widthDiff;
}
return window.outerWidth;
}

0 comments on commit b3156be

Please sign in to comment.