Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed height/width calculations when height/width not numeric values.… #1415

Merged
merged 1 commit into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/commands/view/SelectComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,30 @@ module.exports = {
// Here the resizer is updated with the current element height and width
onStart(e, opts = {}) {
const { el, config, resizer } = opts;
const { keyHeight, keyWidth, currentUnit } = config;
const {
keyHeight,
keyWidth,
currentUnit,
keepAutoHeight,
keepAutoWidth
} = config;
toggleBodyClass('add', e, opts);
modelToStyle = em.get('StyleManager').getModelToStyle(model);
const computedStyle = getComputedStyle(el);
const modelStyle = modelToStyle.getStyle();
const currentWidth = modelStyle[keyWidth] || computedStyle[keyWidth];
const currentHeight =
modelStyle[keyHeight] || computedStyle[keyHeight];

let currentWidth = modelStyle[keyWidth];
config.autoWidth = keepAutoWidth && currentWidth === 'auto';
if (isNaN(parseFloat(currentWidth))) {
currentWidth = computedStyle[keyWidth];
}

let currentHeight = modelStyle[keyHeight];
config.autoHeight = keepAutoHeight && currentHeight === 'auto';
if (isNaN(parseFloat(currentHeight))) {
currentHeight = computedStyle[keyHeight];
}

resizer.startDim.w = parseFloat(currentWidth);
resizer.startDim.h = parseFloat(currentHeight);
showOffsets = 0;
Expand Down Expand Up @@ -405,17 +421,17 @@ module.exports = {
}

const { store, selectedHandler, config } = options;
const { keyHeight, keyWidth } = config;
const { keyHeight, keyWidth, autoHeight, widthAuto } = config;
const onlyHeight = ['tc', 'bc'].indexOf(selectedHandler) >= 0;
const onlyWidth = ['cl', 'cr'].indexOf(selectedHandler) >= 0;
const style = modelToStyle.getStyle();

if (!onlyHeight) {
style[keyWidth] = rect.w + config.unitWidth;
style[keyWidth] = widthAuto ? 'auto' : rect.w + config.unitWidth;
}

if (!onlyWidth) {
style[keyHeight] = rect.h + config.unitHeight;
style[keyHeight] = autoHeight ? 'auto' : rect.h + config.unitHeight;
}

modelToStyle.setStyle(style, { avoidStore: 1 });
Expand Down
12 changes: 12 additions & 0 deletions src/utils/Resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ var defaultOpts = {
// If true the container of handlers won't be updated
avoidContainerUpdate: 0,

// If height is 'auto', this setting will preserve it and only update width
keepAutoHeight: false,

// If width is 'auto', this setting will preserve it and only update height
keepAutoWidth: false,

// When keepAutoHeight is true and the height has the value 'auto', this is set to true and height isn't updated
autoHeight: false,

// When keepAutoWidth is true and the width has the value 'auto', this is set to true and width isn't updated
autoWidth: false,

// Handlers
tl: 1, // Top left
tc: 1, // Top center
Expand Down