mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix review comments
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4bb46a797f
commit
aa1ca11631
@ -41,7 +41,7 @@ export class DockStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get defaultHeight() {
|
get defaultHeight() {
|
||||||
return Math.round(window.innerHeight * 0.4);
|
return Math.round(window.innerHeight / 2.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
get maxHeight() {
|
get maxHeight() {
|
||||||
@ -54,11 +54,7 @@ export class DockStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const stored = this.storage.get()
|
Object.assign(this, this.storage.get());
|
||||||
if (Object.entries(stored).length > 0) {
|
|
||||||
// don't override perfectly good defaults in the class decl
|
|
||||||
Object.assign(this, stored);
|
|
||||||
}
|
|
||||||
|
|
||||||
reaction(() => ({
|
reaction(() => ({
|
||||||
isOpen: this.isOpen,
|
isOpen: this.isOpen,
|
||||||
|
|||||||
@ -172,16 +172,16 @@ export class Terminal {
|
|||||||
// Handle custom hotkey bindings
|
// Handle custom hotkey bindings
|
||||||
if (ctrlKey) {
|
if (ctrlKey) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
// Ctrl+C: prevent terminal exit on windows / linux (?)
|
// Ctrl+C: prevent terminal exit on windows / linux (?)
|
||||||
case "KeyC":
|
case "KeyC":
|
||||||
if (this.xterm.hasSelection()) return false;
|
if (this.xterm.hasSelection()) return false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Ctrl+W: prevent unexpected terminal tab closing, e.g. editing file in vim
|
// Ctrl+W: prevent unexpected terminal tab closing, e.g. editing file in vim
|
||||||
// https://github.com/kontena/lens-app/issues/156#issuecomment-534906480
|
// https://github.com/kontena/lens-app/issues/156#issuecomment-534906480
|
||||||
case "KeyW":
|
case "KeyW":
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ body.resizing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ResizingAnchor {
|
.ResizingAnchor {
|
||||||
$prominentDimention: 12px;
|
$dimension: 12px;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
@ -18,14 +18,14 @@ body.resizing {
|
|||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
cursor: row-resize;
|
cursor: row-resize;
|
||||||
height: $prominentDimention;
|
height: $dimension;
|
||||||
|
|
||||||
&.leading {
|
&.leading {
|
||||||
top: -$prominentDimention / 2;
|
top: -$dimension / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.trailing {
|
&.trailing {
|
||||||
bottom: -$prominentDimention / 2;
|
bottom: -$dimension / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,14 +33,14 @@ body.resizing {
|
|||||||
top: 0;
|
top: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
cursor: col-resize;
|
cursor: col-resize;
|
||||||
width: $prominentDimention;
|
width: $dimension;
|
||||||
|
|
||||||
&.leading {
|
&.leading {
|
||||||
left: -$prominentDimention / 2;
|
left: -$dimension / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.trailing {
|
&.trailing {
|
||||||
right: -$prominentDimention / 2;
|
right: -$dimension / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ interface Props {
|
|||||||
direction: ResizeDirection;
|
direction: ResizeDirection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getCurrentExtent should return the current prominent dimention in the
|
* getCurrentExtent should return the current prominent dimension in the
|
||||||
* given resizing direction. Width for HORIZONTAL and height for VERTICAL
|
* given resizing direction. Width for HORIZONTAL and height for VERTICAL
|
||||||
*/
|
*/
|
||||||
getCurrentExtent: () => number;
|
getCurrentExtent: () => number;
|
||||||
@ -111,40 +111,42 @@ interface Position {
|
|||||||
/**
|
/**
|
||||||
* Return the direction delta, but ignore drags leading up to a moved item
|
* Return the direction delta, but ignore drags leading up to a moved item
|
||||||
* 1. `->|` => return `false`
|
* 1. `->|` => return `false`
|
||||||
* 2. `<-|` => return `directed length (P1, P2)` (negative)
|
* 2. `<-|` => return `directed length (M, P2)` (negative)
|
||||||
* 3. `-|>` => return `directed length (M, P2)` (positive)
|
* 3. `-|>` => return `directed length (M, P2)` (positive)
|
||||||
* 4. `<|-` => return `directed length (M, P2)` (negative)
|
* 4. `<|-` => return `directed length (M, P2)` (negative)
|
||||||
* 5. `|->` => return `directed length (P1, P2)` (positive)
|
* 5. `|->` => return `directed length (M, P2)` (positive)
|
||||||
* 6. `|<-` => return `false`
|
* 6. `|<-` => return `false`
|
||||||
* @param P the starting position on the number line
|
* @param P1 the starting position on the number line
|
||||||
* @param Q the ending position on the number line
|
* @param P2 the ending position on the number line
|
||||||
* @param M a third point that determines if the delta is meaningful
|
* @param M a third point that determines if the delta is meaningful
|
||||||
* @returns the directional difference between including appropriate sign.
|
* @returns the directional difference between including appropriate sign.
|
||||||
*/
|
*/
|
||||||
function directionDelta(P1: number, P2: number, B: number): number | false {
|
function directionDelta(P1: number, P2: number, M: number): number | false {
|
||||||
if (P1 < B) {
|
const delta = Math.abs(M - P2)
|
||||||
if (P2 >= B) {
|
|
||||||
|
if (P1 < M) {
|
||||||
|
if (P2 >= M) {
|
||||||
// case 3
|
// case 3
|
||||||
return Math.abs(B - P2)
|
return delta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (P2 < P1) {
|
if (P2 < P1) {
|
||||||
// case 2
|
// case 2
|
||||||
return -Math.abs(P1 - P2)
|
return -delta
|
||||||
}
|
}
|
||||||
|
|
||||||
// case 1
|
// case 1
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (P2 < B) {
|
if (P2 < M) {
|
||||||
// case 4
|
// case 4
|
||||||
return -Math.abs(B - P2)
|
return -delta
|
||||||
}
|
}
|
||||||
|
|
||||||
if (P1 < P2) {
|
if (P1 < P2) {
|
||||||
// case 5
|
// case 5
|
||||||
return Math.abs(P1 - P2)
|
return delta
|
||||||
}
|
}
|
||||||
|
|
||||||
// case 6
|
// case 6
|
||||||
@ -153,7 +155,7 @@ function directionDelta(P1: number, P2: number, B: number): number | false {
|
|||||||
|
|
||||||
export class ResizingAnchor extends React.PureComponent<Props> {
|
export class ResizingAnchor extends React.PureComponent<Props> {
|
||||||
@observable lastMouseEvent?: MouseEvent
|
@observable lastMouseEvent?: MouseEvent
|
||||||
@observable elem: HTMLElement
|
@observable.ref ref?: React.RefObject<HTMLDivElement>;
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
onStart: noop,
|
onStart: noop,
|
||||||
@ -177,10 +179,8 @@ export class ResizingAnchor extends React.PureComponent<Props> {
|
|||||||
if (props.maxExtent < props.minExtent) {
|
if (props.maxExtent < props.minExtent) {
|
||||||
throw new Error("maxExtent must be >= minExtent")
|
throw new Error("maxExtent must be >= minExtent")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
this.ref = React.createRef<HTMLDivElement>()
|
||||||
this.elem = findDOMNode(this) as HTMLElement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -205,7 +205,12 @@ export class ResizingAnchor extends React.PureComponent<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
calculateDelta(from: Position, to: Position): number | false {
|
calculateDelta(from: Position, to: Position): number | false {
|
||||||
const boundingBox = this.elem.getBoundingClientRect()
|
const node = this.ref.current
|
||||||
|
if (!node) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const boundingBox = node.getBoundingClientRect()
|
||||||
|
|
||||||
if (this.props.direction === ResizeDirection.HORIZONTAL) {
|
if (this.props.direction === ResizeDirection.HORIZONTAL) {
|
||||||
const barX = Math.round(boundingBox.x + (boundingBox.width / 2))
|
const barX = Math.round(boundingBox.x + (boundingBox.width / 2))
|
||||||
@ -242,6 +247,10 @@ export class ResizingAnchor extends React.PureComponent<Props> {
|
|||||||
const { maxExtent, minExtent, getCurrentExtent, growthDirection } = this.props
|
const { maxExtent, minExtent, getCurrentExtent, growthDirection } = this.props
|
||||||
const { onDrag, onMaxExtentExceed, onMinExtentSubceed, onMaxExtentSubceed, onMinExtentExceed } = this.props
|
const { onDrag, onMaxExtentExceed, onMinExtentSubceed, onMaxExtentSubceed, onMinExtentExceed } = this.props
|
||||||
const delta = this.calculateDelta(this.lastMouseEvent, event)
|
const delta = this.calculateDelta(this.lastMouseEvent, event)
|
||||||
|
|
||||||
|
// always update the last mouse event
|
||||||
|
this.lastMouseEvent = event
|
||||||
|
|
||||||
if (delta === false) {
|
if (delta === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -261,12 +270,10 @@ export class ResizingAnchor extends React.PureComponent<Props> {
|
|||||||
} else if (previousExtent >= maxExtent && maxExtent >= unboundedExtent) {
|
} else if (previousExtent >= maxExtent && maxExtent >= unboundedExtent) {
|
||||||
onMaxExtentSubceed()
|
onMaxExtentSubceed()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastMouseEvent = event
|
|
||||||
}, 100)
|
}, 100)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onDragEnd = (event: MouseEvent) => {
|
onDragEnd = (_event: MouseEvent) => {
|
||||||
this.props.onEnd()
|
this.props.onEnd()
|
||||||
document.removeEventListener("mousemove", this.onDrag)
|
document.removeEventListener("mousemove", this.onDrag)
|
||||||
document.removeEventListener("mouseup", this.onDragEnd)
|
document.removeEventListener("mouseup", this.onDragEnd)
|
||||||
@ -275,6 +282,10 @@ export class ResizingAnchor extends React.PureComponent<Props> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { disabled, direction, placement } = this.props
|
const { disabled, direction, placement } = this.props
|
||||||
return <div className={cssNames("ResizingAnchor", direction, placement, { disabled })} onMouseDown={this.onDragInit} />
|
return <div
|
||||||
|
ref={this.ref}
|
||||||
|
className={cssNames("ResizingAnchor", direction, placement, { disabled })}
|
||||||
|
onMouseDown={this.onDragInit}
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user