Skip to content

Commit 5286119

Browse files
Merge pull request #108 from ArthurLobopro/feat-new-resize
Feat new resize
2 parents a533055 + 6453774 commit 5286119

File tree

8 files changed

+85
-27
lines changed

8 files changed

+85
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.25.0
2+
3+
Feat: Window Container can be resized
4+
15
## 1.24.0
26

37
Feat: You can remove any line highlight using `Ctrl` + Click on line number

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "easy-codesnap",
33
"displayName": "Easy CodeSnap",
44
"description": "Take beautiful screenshots of your code 📷",
5-
"version": "1.24.0",
5+
"version": "1.25.0",
66
"l10n": "./l10n",
77
"repository": {
88
"type": "git",

src/webview/ui/elements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const windowNode = $("#window");
3131
export const snippetContainerNode = $("#snippet-container");
3232
export const flashFx = $("#flash-fx");
3333
export const watermarkElement = $("#watermark");
34+
export const targetProportion = $("#target-proportion");
3435

3536
//One time config elements
3637
export const showWindowTitleInput = getToggle("showWindowTitle");

src/webview/ui/listeners/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SessionConfig } from "../../SessionConfig";
2-
import { windowNode } from "../elements";
3-
import { UpdateRatio } from "../updaters";
2+
import { snippetContainerNode, windowNode } from "../elements";
3+
import { UpdateRatio, UpdateTargetProportion } from "../updaters";
44
import { addButtonListeners } from "./addButtonListeners";
55
import { addContentEditableListeners } from "./addContentEditableListeners";
66
import { addHideOneTimeConfigListener } from "./addHideOneTimeConfigListener";
@@ -22,8 +22,11 @@ export function addListeners() {
2222
if (SessionConfig.get("aspectRatio") !== "none") {
2323
UpdateRatio();
2424
}
25+
26+
UpdateTargetProportion();
2527
console.log("Resize");
2628
});
2729

30+
resizeObserver.observe(snippetContainerNode);
2831
resizeObserver.observe(windowNode);
2932
}

src/webview/ui/updaters/VarUpdater.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SessionConfig } from "../../SessionConfig";
22
import { px, setVar } from "../../util";
33
import { Updater } from "../Updater";
4+
import { snippetContainerNode } from "../elements";
45

56
export class VarUpdater extends Updater {
67
constructor() {
@@ -15,6 +16,7 @@ export class VarUpdater extends Updater {
1516
"roundingLevel",
1617
"showLineNumbers",
1718
"letterSpacing",
19+
"target",
1820
]);
1921
}
2022

@@ -30,6 +32,7 @@ export class VarUpdater extends Updater {
3032
roundingLevel,
3133
showLineNumbers,
3234
letterSpacing,
35+
target,
3336
} = SessionConfig.get();
3437

3538
setVar("ligatures", fontLigatures ? "normal" : "none");
@@ -50,7 +53,9 @@ export class VarUpdater extends Updater {
5053
roundedCorners ? px(4 * roundingLevel) : "0",
5154
);
5255

53-
setVar("enable-resizing", enableResizing ? "horizontal" : "none");
5456
setVar("line-number-visibility", showLineNumbers ? "block" : "none");
57+
58+
snippetContainerNode.dataset.enableresizing = String(enableResizing);
59+
snippetContainerNode.dataset.target = target;
5560
}
5661
}

src/webview/ui/updaters/VisibilityUpdater.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
saveScaleSelect,
1111
shutterActionSelect,
1212
snippetContainerNode,
13+
targetProportion,
1314
targetSelect,
1415
windowControlsNode,
1516
windowNode,
@@ -24,6 +25,7 @@ export class VisibilityUpdater extends Updater {
2425
"aspectRatio",
2526
"highlightLineNumber",
2627
"enableResizing",
28+
"target",
2729
]);
2830
}
2931

@@ -49,8 +51,11 @@ export class VisibilityUpdater extends Updater {
4951

5052
if (!enableResizing) {
5153
windowNode.style.width = "";
54+
snippetContainerNode.style.width = "";
5255
}
5356

57+
UpdateTargetProportion();
58+
5459
const selects = [
5560
targetSelect,
5661
shutterActionSelect,
@@ -77,6 +82,18 @@ export class VisibilityUpdater extends Updater {
7782
}
7883
}
7984

85+
export function UpdateTargetProportion() {
86+
const target = SessionConfig.get("target");
87+
88+
if (target === "container") {
89+
const { width, height } = snippetContainerNode.getBoundingClientRect();
90+
targetProportion.innerText = `${width.toFixed(0)} x ${height.toFixed(0)}`;
91+
} else {
92+
const { width, height } = windowNode.getBoundingClientRect();
93+
targetProportion.innerText = `${width.toFixed(0)} x ${height.toFixed(0)}`;
94+
}
95+
}
96+
8097
export function UpdateRatio(
8198
aspectRatio: WebviewConfig["aspectRatio"] = SessionConfig.get(
8299
"aspectRatio",

webview/index.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -324,28 +324,31 @@
324324
<span class="tooltip-text">Take Snap</span>
325325
</div>
326326

327-
<div id="snippet-scroll">
328-
<div id="snippet-container">
329-
<div id="window" data-style="macos">
330-
<div id="watermark"></div>
331-
<div id="navbar">
332-
<div id="window-controls">
333-
<div class="red dot"></div>
334-
<div class="yellow dot"></div>
335-
<div class="green dot"></div>
336-
<div class="button">
337-
<insert-svg src="./assets/windows/minimize.svg"></insert-svg>
338-
</div>
339-
<div class="button">
340-
<insert-svg src="./assets/windows/maximize.svg"></insert-svg>
341-
</div>
342-
<div class="button">
343-
<insert-svg src="./assets/windows/close.svg"></insert-svg>
327+
<div>
328+
<div id="target-proportion"></div>
329+
<div id="snippet-scroll">
330+
<div id="snippet-container">
331+
<div id="window" data-style="macos">
332+
<div id="watermark"></div>
333+
<div id="navbar">
334+
<div id="window-controls">
335+
<div class="red dot"></div>
336+
<div class="yellow dot"></div>
337+
<div class="green dot"></div>
338+
<div class="button">
339+
<insert-svg src="./assets/windows/minimize.svg"></insert-svg>
340+
</div>
341+
<div class="button">
342+
<insert-svg src="./assets/windows/maximize.svg"></insert-svg>
343+
</div>
344+
<div class="button">
345+
<insert-svg src="./assets/windows/close.svg"></insert-svg>
346+
</div>
344347
</div>
348+
<div id="window-title"></div>
345349
</div>
346-
<div id="window-title"></div>
350+
<div id="snippet"></div>
347351
</div>
348-
<div id="snippet"></div>
349352
</div>
350353
</div>
351354
</div>

webview/styles/original-style.css

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ html {
66
--box-shadow: rgba(0, 0, 0, 0.55) 0px 20px 68px;
77
--container-padding: 3em;
88
--window-border-radius: 4px;
9-
--enable-resizing: horizontal;
109
--letter-spacing: 0px;
1110
--zoom: 100%;
12-
11+
1312
box-sizing: border-box;
1413
}
1514

@@ -28,21 +27,48 @@ code {
2827
color: currentColor;
2928
}
3029

30+
div:has(#snippet-scroll) {
31+
display: flex;
32+
flex-direction: column;
33+
align-items: end;
34+
max-width: 100%;
35+
gap: 4px;
36+
}
37+
3138
#snippet-scroll {
3239
max-width: 100%;
3340
overflow-x: auto;
3441
margin: auto;
3542
zoom: var(--zoom);
3643
}
3744

45+
#target-proportion {
46+
color: var(--vscode-foreground);
47+
background-color: var(--vscode-sideBar-background);
48+
padding: 4px;
49+
border-radius: 6px 4px;
50+
}
51+
3852
#snippet-container {
3953
display: flex;
4054
justify-content: center;
4155
align-items: center;
4256
padding: var(--container-padding);
4357
background: var(--container-background-color);
44-
width: max-content;
58+
min-width: max-content;
59+
min-height: max-content;
4560
box-sizing: border-box;
61+
62+
&[data-enableresizing="true"] {
63+
&:is([data-target="container"]) {
64+
overflow: hidden;
65+
resize: both;
66+
}
67+
68+
#window {
69+
resize: horizontal;
70+
}
71+
}
4672
}
4773

4874
#window {
@@ -51,7 +77,6 @@ code {
5177
border-radius: var(--window-border-radius);
5278
box-shadow: var(--box-shadow);
5379
overflow: hidden;
54-
resize: var(--enable-resizing);
5580
width: max-content;
5681
min-width: 100px;
5782
padding: 18px;

0 commit comments

Comments
 (0)