Lock hunks when viewing remote files

- readonly prop for hunks to disable cursor and dragging
- removes a console.log
- undo a previous change related to AnyFile
- fix gap between text selection blocks line numbers
This commit is contained in:
Mattias Granlund 2024-02-01 16:00:43 +01:00
parent 90e7b0f192
commit e5fe606ab0
8 changed files with 23 additions and 9 deletions

View File

@ -12,18 +12,18 @@
export let showCheckboxes = false;
export let selectedFiles: Writable<AnyFile[]>;
export let allowMultiple = false;
$: console.log(selectedFiles);
export let readonly = false;
</script>
{#each sortLikeFileTree(files) as file (file.id)}
<FileListItem
{file}
{isUnapplied}
{readonly}
{branchId}
{isUnapplied}
{selectedFiles}
{selectedOwnership}
showCheckbox={showCheckboxes}
{selectedFiles}
on:click={(e) => {
const isAlreadySelected = $selectedFiles.includes(file);
if (isAlreadySelected && e.shiftKey) {

View File

@ -78,6 +78,7 @@
{branchController}
{selectedOwnership}
{isUnapplied}
readonly={selected instanceof RemoteFile}
selectable={$commitBoxOpen && !isUnapplied}
on:close={() => {
const selectedId = selected?.id;

View File

@ -113,6 +113,7 @@
{selectedOwnership}
{selectedFiles}
{isUnapplied}
readonly={true}
/>
{:else}
<FileTree
@ -174,6 +175,7 @@
<div class="commit-modal__code-container custom-scrollbar">
<div class="commit-modal__code-wrapper">
<FileDiff
readonly={true}
filePath={remoteFile.path}
isBinary={remoteFile.binary}
isLarge={false}

View File

@ -23,6 +23,7 @@
export let branchController: BranchController;
export let isUnapplied: boolean;
export let selectable = false;
export let readonly = false;
export let selectedOwnership: Writable<Ownership>;
let rsViewport: HTMLElement;
@ -74,6 +75,7 @@
filePath={file.path}
isLarge={file.large}
isBinary={file.binary}
{readonly}
{sections}
{projectPath}
{isFileLocked}

View File

@ -18,6 +18,7 @@
export let selectable = false;
export let selectedOwnership: Writable<Ownership> | undefined = undefined;
export let isFileLocked = false;
export let readonly: boolean = false;
function getGutterMinWidth(max: number) {
if (max >= 10000) return 2.5;
@ -61,6 +62,7 @@
{branchController}
{isFileLocked}
{minWidth}
{readonly}
/>
</div>
{/if}

View File

@ -15,6 +15,7 @@
export let showCheckbox: boolean = false;
export let selectedOwnership: Writable<Ownership>;
export let selectedFiles: Writable<AnyFile[]>;
export let readonly = false;
let checked = false;
let indeterminate = false;
@ -40,7 +41,7 @@
}}
use:draggable={{
...draggableFile(branchId, file, selectedFiles),
disabled: isUnapplied,
disabled: readonly || isUnapplied,
selector: '.selected-draggable'
}}
role="button"

View File

@ -10,6 +10,7 @@
export let minWidth = 1.75;
export let selectable: boolean = false;
export let selected: boolean = true;
export let readonly: boolean = false;
const dispatch = createEventDispatcher<{ selected: boolean }>();
@ -59,6 +60,7 @@
</div>
<div
class="line"
class:readonly
class:diff-line-deletion={sectionType === SectionType.RemovedLines}
class:diff-line-addition={sectionType === SectionType.AddedLines}
>
@ -80,8 +82,9 @@
.line {
flex-grow: 1;
cursor: grab;
padding-left: var(--space-4);
&:not(.readonly) {
cursor: grab;
}
}
.code-line__numbers-line {
@ -93,5 +96,6 @@
.selectable-wrapper {
cursor: text;
display: inline-block;
text-indent: var(--space-4);
}
</style>

View File

@ -19,6 +19,7 @@
export let selectable = false;
export let isUnapplied: boolean;
export let isFileLocked: boolean;
export let readonly: boolean = false;
export let branchController: BranchController;
export let selectedOwnership: Writable<Ownership> | undefined = undefined;
@ -54,10 +55,11 @@
role="cell"
use:draggable={{
...draggableHunk(branchId, section.hunk),
disabled: isUnapplied || section.hunk.locked || !branchId
disabled: readonly || isUnapplied || section.hunk.locked || !branchId
}}
on:contextmenu|preventDefault
class="hunk"
class:readonly
class:opacity-60={section.hunk.locked && !isFileLocked}
>
<div class="hunk__bg-stretch">
@ -67,6 +69,7 @@
<HunkLine
{line}
{filePath}
{readonly}
{minWidth}
{selectable}
selected={$selectedOwnership?.containsHunk(hunk.filePath, hunk.id)}
@ -89,7 +92,6 @@
display: flex;
flex-direction: column;
overflow-x: auto;
cursor: grab;
background: var(--clr-theme-container-light);
border-radius: var(--radius-s);