Skip to content

Commit

Permalink
Paste feature requested on #48 (#52)
Browse files Browse the repository at this point in the history
* paste feature requested on #48

* fix merge conflicts and use netmask
  • Loading branch information
ranga543 authored May 30, 2023
1 parent 615db86 commit 8a4372c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class IPAddress extends Component {
};
this.handleChange = this.handleChange.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handlePaste = this.handlePaste.bind(this);
this.handleWheel = this.handleWheel.bind(this);
}

Expand Down Expand Up @@ -65,6 +66,26 @@ class IPAddress extends Component {
}
}

handlePaste(event) {
const pasteText = event.clipboardData.getData('Text');
var details = new Netmask(pasteText);
const cidrParts = details.toString().split('/');
var octets = this.state.octets;
const octetParts = cidrParts[0].split('.');
octetParts.map((octet, i) => {
octets[i] = octet;
})
this.setState({
octets: octets
});

if (+cidrParts[1] <= 32) {
this.setState({
cidr: +cidrParts[1]
});
}
}

handleWheel(event) {
var lowerOctetValue = 0;
var higherOctetValue = event.target.dataset.octet === 'cidr' ? 32 : 255;
Expand Down Expand Up @@ -96,6 +117,7 @@ class IPAddress extends Component {
data-octet={octet}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
onPaste={this.handlePaste}
onWheel={this.handleWheel}
value={this.state.octets[octet]}
/>
Expand All @@ -108,6 +130,7 @@ class IPAddress extends Component {
data-octet="cidr"
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
onPaste={this.handlePaste}
onWheel={this.handleWheel}
value={this.state.cidr}
/>
Expand Down

0 comments on commit 8a4372c

Please sign in to comment.